Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1
Default 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   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 860
Default 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   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 12
Default 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   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 213
Default 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   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 7,247
Default 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
Search this Thread:

Advanced Search
Display Modes

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
eula pops up every time i open an office program. office 2003 ins. ijscholl Excel Discussion (Misc queries) 0 July 28th 09 11:54 PM
How can I open a Open Office Calc (ods) file in excel bradley kincade Excel Discussion (Misc queries) 1 December 12th 08 09:34 AM
MS Office 07. Notice says A prob caused the prog to stop working Geoff Valentine New Users to Excel 0 September 22nd 08 03:13 AM
Unable to open Office 2007 files using Office 2002 XP GildaBB Excel Discussion (Misc queries) 2 July 20th 07 04:08 AM
Problem of Open Office and MS Office PKH Excel Worksheet Functions 0 March 4th 05 02:30 AM


All times are GMT +1. The time now is 03:05 AM.

Powered by vBulletin® Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
Copyright ©2004-2024 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"