Jump to content
The mkiv Supra Owners Club

VBA Quicky Help


Scott

Recommended Posts

I am creating a little program to help me out at work. Using Excel I am trying to create a link so that when a button is clicked a Word document is opened. So far I have this..

 

AppActivate Shell("C:\Program Files\Microsoft Office\Office\Winword.exe C:\Test1.Doc")

 

Now this works fine. However, if I want the document to be in a folder on the desktop the code should read..

 

AppActivate Shell("C:\Program Files\Microsoft Office\Office\Winword.exe C:\Documents and Settings\uBlahblah\Desktop\Calibration\Test1.Doc")

 

This doesn't work due to the spaces in "Documents and Settings". I have tried putting in "" on either side of the path but it rejects it. Some of the filenames I wish to open also have spaces.. same issue.

 

I'm sure it will be a simple fix but I can't find it at the mo.

 

Can anyone help?

Link to comment
Share on other sites

its seems it may be an issue with VBA and long file names, there maybe an API to work around it.

 

here is a function that will convert to short file names.

 

Private Declare Function GetShortPathName Lib "kernel32" Alias "GetShortPathNameA" (ByVal lpszLongPath As String, ByVal lpszShortPath As String, ByVal lBuffer As Long) As Long

Public Function GetShortPath(strFileName As String) As String

'KPD-Team 1999

'URL: http://www.allapi.net/

'E-Mail: [email protected]

Dim lngRes As Long, strPath As String

'Create a buffer

strPath = String$(165, 0)

'retrieve the short pathname

lngRes = GetShortPathName(strFileName, strPath, 164)

'remove all unnecessary chr$(0)'s

GetShortPath = Left$(strPath, lngRes)

End Function

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue. You might also be interested in our Guidelines, Privacy Policy and Terms of Use.