Open File using Variable Path?

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Jason Gyetko

    #1

    Open File using Variable Path?

    I'm trying to open a file from VBA using a variable path and am not
    having very much luck. Can anyone help?

    This works:
    retval = Shell("""Excel. EXE"" ""C:\Progra m files\MyPath\My File.xls""",
    1)

    This does not like the space in 'Program Files':
    retval = Shell("Excel.EX E " & Application.Cur rentProject.Pat h &
    "\MyFile.xl s", 1)

    I've tried quotation marks all over the place in all sorts of
    combinations and cannot get it to work. With the above example I get
    the following message:

    'C:\Program.xls ' could not be found...

    That one is immediately followed by:

    'Files\MyPath\M yFile.xls' could not be found.

    Thanks in advance for any suggestions.

  • Terry Kreft

    #2
    Re: Open File using Variable Path?

    You've got the pairs of double quotes missing, try

    retval = Shell("Excel.EX E """ & Application.Cur rentProject.Pat h &
    "\MyFile.xls""" , 1)


    --

    Terry Kreft


    "Jason Gyetko" <jason.gyetko@e power-inc.comwrote in message
    news:1156346573 .219816.313750@ b28g2000cwb.goo glegroups.com.. .
    I'm trying to open a file from VBA using a variable path and am not
    having very much luck. Can anyone help?
    >
    This works:
    retval = Shell("""Excel. EXE"" ""C:\Progra m files\MyPath\My File.xls""",
    1)
    >
    This does not like the space in 'Program Files':
    retval = Shell("Excel.EX E " & Application.Cur rentProject.Pat h &
    "\MyFile.xl s", 1)
    >
    I've tried quotation marks all over the place in all sorts of
    combinations and cannot get it to work. With the above example I get
    the following message:
    >
    'C:\Program.xls ' could not be found...
    >
    That one is immediately followed by:
    >
    'Files\MyPath\M yFile.xls' could not be found.
    >
    Thanks in advance for any suggestions.
    >

    Comment

    • Jason Gyetko

      #3
      Re: Open File using Variable Path?

      Thanks, that worked. Not sure why it was so difficult, seemed like I
      tried quotes in every possible combination.

      Terry Kreft wrote:
      You've got the pairs of double quotes missing, try
      >
      retval = Shell("Excel.EX E """ & Application.Cur rentProject.Pat h &
      "\MyFile.xls""" , 1)
      >
      >
      --
      >
      Terry Kreft
      >
      >
      "Jason Gyetko" <jason.gyetko@e power-inc.comwrote in message
      news:1156346573 .219816.313750@ b28g2000cwb.goo glegroups.com.. .
      I'm trying to open a file from VBA using a variable path and am not
      having very much luck. Can anyone help?

      This works:
      retval = Shell("""Excel. EXE"" ""C:\Progra m files\MyPath\My File.xls""",
      1)

      This does not like the space in 'Program Files':
      retval = Shell("Excel.EX E " & Application.Cur rentProject.Pat h &
      "\MyFile.xl s", 1)

      I've tried quotation marks all over the place in all sorts of
      combinations and cannot get it to work. With the above example I get
      the following message:

      'C:\Program.xls ' could not be found...

      That one is immediately followed by:

      'Files\MyPath\M yFile.xls' could not be found.

      Thanks in advance for any suggestions.

      Comment

      Working...