Home |
Search |
Today's Posts |
#1
Posted to microsoft.public.excel.programming
|
|||
|
|||
Open non-Office prog. macro
Just a warning - I'm not very well versed in VB like this. Here's what I
want to do: Off of a button in Excel, I want to open a shortcut to another document (non-office document)which is on my desktop. Let's just say the document's name is "ABC" for the example. Can someone help me with what the macro text would look like? TIA -Steve (operating in XP) |
#2
Posted to microsoft.public.excel.programming
|
|||
|
|||
Open non-Office prog. macro
Hi Schneider_4,
You can use the Windows API to do this. Here's some sample code: '/ ---------BEGIN CODE--------- Public Const SW_SHOWMAXIMIZED = 3 Public Const ERROR_FILE_NOT_FOUND = 2& Public Declare Function ShellExecute Lib "shell32.dll" _ Alias "ShellExecuteA" (ByVal hwnd As Long, _ ByVal lpOperation As String, ByVal lpFile As String, _ ByVal lpParameters As String, ByVal lpDirectory As String, _ ByVal nShowCmd As Long) As Long Public Function gbOpenDocument(rsFullPath As String, _ rsErrMsg As String) As Boolean Dim lResponse As Long lResponse = ShellExecute(Application.hwnd, _ "open" & vbNullChar, rsFullPath & vbNullChar, _ vbNull, vbNull, SW_SHOWMAXIMIZED) If lResponse = ERROR_FILE_NOT_FOUND Then rsErrMsg _ = "File not found." gbOpenDocument = (lResponse 32) End Function '/ ---------END CODE--------- To use this, just follow these steps: 1) Paste the above code into a Standard Module in the VBE (Alt+F11 to get there) 2) To open a document, your code would just look something like this: '/ ---------BEGIN CODE--------- Sub demo() Dim sErr As String Dim sPath As String sPath = "C:\test.gif" If Not gbOpenDocument(sPath, sErr) Then MsgBox "Error opening '" & sPath & "': " _ & sErr, vbExclamation, "Error" End If End Sub '/ ---------END CODE--------- -- Regards, Jake Marx MS MVP - Excel www.longhead.com [please keep replies in the newsgroup - email address unmonitored] Schneider_4 wrote: Just a warning - I'm not very well versed in VB like this. Here's what I want to do: Off of a button in Excel, I want to open a shortcut to another document (non-office document)which is on my desktop. Let's just say the document's name is "ABC" for the example. Can someone help me with what the macro text would look like? TIA -Steve (operating in XP) |
#3
Posted to microsoft.public.excel.programming
|
|||
|
|||
Open non-Office prog. macro
Here is the simple version:
Sub Makro1() Shell "cmd.exe /c start C:\document.pdf" End Sub Greetings Jonjo "Schneider_4" wrote: Just a warning - I'm not very well versed in VB like this. Here's what I want to do: Off of a button in Excel, I want to open a shortcut to another document (non-office document)which is on my desktop. Let's just say the document's name is "ABC" for the example. Can someone help me with what the macro text would look like? TIA -Steve (operating in XP) |
#4
Posted to microsoft.public.excel.programming
|
|||
|
|||
Open non-Office prog. macro
FYI
Learned from using this example code. The cmd.exe shell is limited to the old DOS 8.3 file naming conventions. Thus, a path string like "C:\Mydocument.pdf" would be condensed to "C:\Mydocu~1.pdf" -- Regards Rick XP Pro Office 2007 "jonjo" wrote: Here is the simple version: Sub Makro1() Shell "cmd.exe /c start C:\document.pdf" End Sub Greetings Jonjo "Schneider_4" wrote: Just a warning - I'm not very well versed in VB like this. Here's what I want to do: Off of a button in Excel, I want to open a shortcut to another document (non-office document)which is on my desktop. Let's just say the document's name is "ABC" for the example. Can someone help me with what the macro text would look like? TIA -Steve (operating in XP) |
#5
Posted to microsoft.public.excel.programming
|
|||
|
|||
Open non-Office prog. macro
And if you need to convert to an 8.3 name from a long file name, use
Public Declare Function GetShortPathName Lib "kernel32" Alias "GetShortPathNameA" ( _ ByVal lpszLongPath As String, _ ByVal lpszShortPath As String, _ ByVal cchBuffer As Long) As Long Function ShortFileName(LongFileName As String) As String Dim S As String Dim L As Long Dim R As Long L = 260 S = String$(L, vbNullChar) R = GetShortPathName(LongFileName, S, L) If R Then ShortFileName = Left(S, R) Else ShortFileName = vbNullString End If End Function -- Cordially, Chip Pearson Microsoft MVP - Excel Pearson Software Consulting www.cpearson.com (email on the web site) "Rick S." wrote in message ... FYI Learned from using this example code. The cmd.exe shell is limited to the old DOS 8.3 file naming conventions. Thus, a path string like "C:\Mydocument.pdf" would be condensed to "C:\Mydocu~1.pdf" -- Regards Rick XP Pro Office 2007 "jonjo" wrote: Here is the simple version: Sub Makro1() Shell "cmd.exe /c start C:\document.pdf" End Sub Greetings Jonjo "Schneider_4" wrote: Just a warning - I'm not very well versed in VB like this. Here's what I want to do: Off of a button in Excel, I want to open a shortcut to another document (non-office document)which is on my desktop. Let's just say the document's name is "ABC" for the example. Can someone help me with what the macro text would look like? TIA -Steve (operating in XP) |
Reply |
Thread Tools | Search this Thread |
Display Modes | |
|
|
Similar Threads | ||||
Thread | Forum | |||
eula pops up every time i open an office program. office 2003 ins. | Excel Discussion (Misc queries) | |||
How can I open a Open Office Calc (ods) file in excel | Excel Discussion (Misc queries) | |||
MS Office 07. Notice says A prob caused the prog to stop working | New Users to Excel | |||
Unable to open Office 2007 files using Office 2002 XP | Excel Discussion (Misc queries) | |||
Problem of Open Office and MS Office | Excel Worksheet Functions |