Home |
Search |
Today's Posts |
#1
![]()
Posted to microsoft.public.excel.programming
|
|||
|
|||
![]()
Excel XP & Win XP
I'm trying to get the code for opening a pdf file with my Adobe Reader. I can easily open the file by just double-clicking the file name, but not by code, so the reader is operating correctly. What is the proper code syntax to open, say, "TheFile.pdf", in the path "ThePath"? Thanks for your time. Otto |
#2
![]()
Posted to microsoft.public.excel.programming
|
|||
|
|||
![]()
Private Sub CommandButton1_Click()
Shell "Start.exe ""D:\My Documents\sm569_Jan2001\tute6.pdf""" End Sub -- Regards, Tom Ogilvy "Otto Moehrbach" wrote: Excel XP & Win XP I'm trying to get the code for opening a pdf file with my Adobe Reader. I can easily open the file by just double-clicking the file name, but not by code, so the reader is operating correctly. What is the proper code syntax to open, say, "TheFile.pdf", in the path "ThePath"? Thanks for your time. Otto |
#3
![]()
Posted to microsoft.public.excel.programming
|
|||
|
|||
![]()
Tom
I think I am misreading what you wrote. Here is what I have written from what you said. I get an error that the file is not found. Sub OttoMacroC1() OpenExcelFilepdf ("C1") End Sub Sub OpenExcelFilepdf(WhichFile As String) ThePath = "C:\LettersForms\Ops Manuals\" TheFile = WhichFile & " Ops Manual.pdf" Shell "Start.exe" & ThePath & TheFile End Sub There is a file named "C1 Ops Manual.pdf" in the cited path. Thanks for your help with this. Otto "Tom Ogilvy" wrote in message ... Private Sub CommandButton1_Click() Shell "Start.exe ""D:\My Documents\sm569_Jan2001\tute6.pdf""" End Sub -- Regards, Tom Ogilvy "Otto Moehrbach" wrote: Excel XP & Win XP I'm trying to get the code for opening a pdf file with my Adobe Reader. I can easily open the file by just double-clicking the file name, but not by code, so the reader is operating correctly. What is the proper code syntax to open, say, "TheFile.pdf", in the path "ThePath"? Thanks for your time. Otto |
#4
![]()
Posted to microsoft.public.excel.programming
|
|||
|
|||
![]()
Yes, it appears you did misread it:
Sub OpenExcelFilepdf(WhichFile As String) ThePath = "C:\LettersForms\Ops Manuals\" TheFile = WhichFile & " Ops Manual.pdf" Shell "Start.exe """ & ThePath & TheFile & """" End Sub Note the space after Start.exe and the additional quotes. Demo'd from the immediate window: ThePath = "C:\LettersForms\Ops Manuals\" Whichfile = "C1" TheFile = WhichFile & " Ops Manual.pdf" ? "Start.exe """ & ThePath & TheFile & """" Start.exe "C:\LettersForms\Ops Manuals\C1 Ops Manual.pdf" shows you want the argument passed to Shell looks like. If you still have problems, you might need to put single quotes in so it ends up being Start.exe "'C:\LettersForms\Ops Manuals\C1 Ops Manual.pdf'" because of the spaces in the names. However, the example I posted has spaces in the path and it worked, so I think yours will work without single quotes as well. -- Regards, Tom Ogilvy -- Regards, Tom Ogilvy -- regards, Tom Ogilvy "Otto Moehrbach" wrote: Tom I think I am misreading what you wrote. Here is what I have written from what you said. I get an error that the file is not found. Sub OttoMacroC1() OpenExcelFilepdf ("C1") End Sub Sub OpenExcelFilepdf(WhichFile As String) ThePath = "C:\LettersForms\Ops Manuals\" TheFile = WhichFile & " Ops Manual.pdf" Shell "Start.exe" & ThePath & TheFile End Sub There is a file named "C1 Ops Manual.pdf" in the cited path. Thanks for your help with this. Otto "Tom Ogilvy" wrote in message ... Private Sub CommandButton1_Click() Shell "Start.exe ""D:\My Documents\sm569_Jan2001\tute6.pdf""" End Sub -- Regards, Tom Ogilvy "Otto Moehrbach" wrote: Excel XP & Win XP I'm trying to get the code for opening a pdf file with my Adobe Reader. I can easily open the file by just double-clicking the file name, but not by code, so the reader is operating correctly. What is the proper code syntax to open, say, "TheFile.pdf", in the path "ThePath"? Thanks for your time. Otto |
#5
![]()
Posted to microsoft.public.excel.programming
|
|||
|
|||
![]() Shell "Start.exe ""D:\My Documents\sm569_Jan2001\tute6.pdf""" Start.exe isn't available on all platforms -- at least that has been my experience on Windows XP Pro and Vista. For example, I don't have it here on my laptop with Windows Vista Ultimate (Shell errors with "53 - File Not Found"). Instead, you can use FindExecutable, which will work on any platform, to find the exe file associated with the file and Shell to that exe passing the file name to the exe. Note that the file passed in to FindExecutable must exist. If it doesn't FindExecutable will fail. A result = 32 from FindExecutable indicates success. Change the value of PDFFileName to the fully-qualified name of your PDF file. Public Declare Function FindExecutable Lib "shell32.dll" _ Alias "FindExecutableA" ( _ ByVal lpFile As String, _ ByVal lpDirectory As String, _ ByVal lpResult As String) As Long Const C_MIN_FINDEXE_SUCCESS_VALUE = 32 Const MAX_PATH = 260 Sub ShellToExe() '''''''''''''''''''''''''''''''''''' ' Shells to the exe associated with ' PDFFileName and opens PDFFileName. '''''''''''''''''''''''''''''''''''' Dim ExeName As String Dim Pos As Integer Dim PDFFileName As String Dim Res As Long ' allocate space in ExeName variable. ExeName = String$(MAX_PATH, vbNullChar) ' CHANGE FILE NAME PDFFileName = "C:\Whatever\FileName.pdf" '<<< File MUST exist If Dir(PDFFileName, vbNormal) = vbNullString Then MsgBox "File: " & PDFFileName & " does not exist." & vbCrLf & _ "'FindExecutable' requires an existing file name." Exit Sub End If ' Get the exe name associated with "pdf". Res = FindExecutable(PDFFileName, vbNullString, ExeName) If Res = C_MIN_FINDEXE_SUCCESS_VALUE Then ' trim off trailing vbNullChar characters Pos = InStr(1, ExeName, vbNullChar, vbBinaryCompare) If Pos Then ExeName = Left(ExeName, Pos - 1) End If Shell Chr(34) & ExeName & Chr(34) & Chr(32) & _ Chr(34) & PDFFileName & Chr(34),vbMaximizedFocus Else MsgBox "Error From FindExecutable: " & CStr(Res) End If End Sub -- Cordially, Chip Pearson Microsoft MVP - Excel Pearson Software Consulting, LLC www.cpearson.com (email on the web site) "Tom Ogilvy" wrote in message ... Private Sub CommandButton1_Click() Shell "Start.exe ""D:\My Documents\sm569_Jan2001\tute6.pdf""" End Sub -- Regards, Tom Ogilvy "Otto Moehrbach" wrote: Excel XP & Win XP I'm trying to get the code for opening a pdf file with my Adobe Reader. I can easily open the file by just double-clicking the file name, but not by code, so the reader is operating correctly. What is the proper code syntax to open, say, "TheFile.pdf", in the path "ThePath"? Thanks for your time. Otto |
#6
![]()
Posted to microsoft.public.excel.programming
|
|||
|
|||
![]()
Tom
Thanks for your help but it's not working. I ran the following macro to make sure my path and file name are correct. I get "True": Sub TestFileExists() Dim bFileExists As Boolean Dim rsFullPath As String rsFullPath = "C:\LettersForms/Ops Manuals\C1 Ops Manual.pdf" bFileExists = Len(Dir$(rsFullPath)) MsgBox bFileExists End Sub I am running the following and I get a "File not found" error. Your help is greatly appreciated. Otto Sub OttoMacroC1() OpenExcelFilepdf ("C1") End Sub Sub OpenExcelFilepdf(WhichFile As String) ThePath = "C:\LettersForms\Ops Manuals\" TheFile = WhichFile & " Ops Manual.pdf" Shell "Start.exe """ & ThePath & TheFile & """" End Sub "Tom Ogilvy" wrote in message ... Yes, it appears you did misread it: Sub OpenExcelFilepdf(WhichFile As String) ThePath = "C:\LettersForms\Ops Manuals\" TheFile = WhichFile & " Ops Manual.pdf" Shell "Start.exe """ & ThePath & TheFile & """" End Sub Note the space after Start.exe and the additional quotes. Demo'd from the immediate window: ThePath = "C:\LettersForms\Ops Manuals\" Whichfile = "C1" TheFile = WhichFile & " Ops Manual.pdf" ? "Start.exe """ & ThePath & TheFile & """" Start.exe "C:\LettersForms\Ops Manuals\C1 Ops Manual.pdf" shows you want the argument passed to Shell looks like. If you still have problems, you might need to put single quotes in so it ends up being Start.exe "'C:\LettersForms\Ops Manuals\C1 Ops Manual.pdf'" because of the spaces in the names. However, the example I posted has spaces in the path and it worked, so I think yours will work without single quotes as well. -- Regards, Tom Ogilvy -- Regards, Tom Ogilvy -- regards, Tom Ogilvy "Otto Moehrbach" wrote: Tom I think I am misreading what you wrote. Here is what I have written from what you said. I get an error that the file is not found. Sub OttoMacroC1() OpenExcelFilepdf ("C1") End Sub Sub OpenExcelFilepdf(WhichFile As String) ThePath = "C:\LettersForms\Ops Manuals\" TheFile = WhichFile & " Ops Manual.pdf" Shell "Start.exe" & ThePath & TheFile End Sub There is a file named "C1 Ops Manual.pdf" in the cited path. Thanks for your help with this. Otto "Tom Ogilvy" wrote in message ... Private Sub CommandButton1_Click() Shell "Start.exe ""D:\My Documents\sm569_Jan2001\tute6.pdf""" End Sub -- Regards, Tom Ogilvy "Otto Moehrbach" wrote: Excel XP & Win XP I'm trying to get the code for opening a pdf file with my Adobe Reader. I can easily open the file by just double-clicking the file name, but not by code, so the reader is operating correctly. What is the proper code syntax to open, say, "TheFile.pdf", in the path "ThePath"? Thanks for your time. Otto |
#7
![]()
Posted to microsoft.public.excel.programming
|
|||
|
|||
![]()
Use Chip's method.
-- Regards, Tom Ogilvy "Otto Moehrbach" wrote: Tom Thanks for your help but it's not working. I ran the following macro to make sure my path and file name are correct. I get "True": Sub TestFileExists() Dim bFileExists As Boolean Dim rsFullPath As String rsFullPath = "C:\LettersForms/Ops Manuals\C1 Ops Manual.pdf" bFileExists = Len(Dir$(rsFullPath)) MsgBox bFileExists End Sub I am running the following and I get a "File not found" error. Your help is greatly appreciated. Otto Sub OttoMacroC1() OpenExcelFilepdf ("C1") End Sub Sub OpenExcelFilepdf(WhichFile As String) ThePath = "C:\LettersForms\Ops Manuals\" TheFile = WhichFile & " Ops Manual.pdf" Shell "Start.exe """ & ThePath & TheFile & """" End Sub "Tom Ogilvy" wrote in message ... Yes, it appears you did misread it: Sub OpenExcelFilepdf(WhichFile As String) ThePath = "C:\LettersForms\Ops Manuals\" TheFile = WhichFile & " Ops Manual.pdf" Shell "Start.exe """ & ThePath & TheFile & """" End Sub Note the space after Start.exe and the additional quotes. Demo'd from the immediate window: ThePath = "C:\LettersForms\Ops Manuals\" Whichfile = "C1" TheFile = WhichFile & " Ops Manual.pdf" ? "Start.exe """ & ThePath & TheFile & """" Start.exe "C:\LettersForms\Ops Manuals\C1 Ops Manual.pdf" shows you want the argument passed to Shell looks like. If you still have problems, you might need to put single quotes in so it ends up being Start.exe "'C:\LettersForms\Ops Manuals\C1 Ops Manual.pdf'" because of the spaces in the names. However, the example I posted has spaces in the path and it worked, so I think yours will work without single quotes as well. -- Regards, Tom Ogilvy -- Regards, Tom Ogilvy -- regards, Tom Ogilvy "Otto Moehrbach" wrote: Tom I think I am misreading what you wrote. Here is what I have written from what you said. I get an error that the file is not found. Sub OttoMacroC1() OpenExcelFilepdf ("C1") End Sub Sub OpenExcelFilepdf(WhichFile As String) ThePath = "C:\LettersForms\Ops Manuals\" TheFile = WhichFile & " Ops Manual.pdf" Shell "Start.exe" & ThePath & TheFile End Sub There is a file named "C1 Ops Manual.pdf" in the cited path. Thanks for your help with this. Otto "Tom Ogilvy" wrote in message ... Private Sub CommandButton1_Click() Shell "Start.exe ""D:\My Documents\sm569_Jan2001\tute6.pdf""" End Sub -- Regards, Tom Ogilvy "Otto Moehrbach" wrote: Excel XP & Win XP I'm trying to get the code for opening a pdf file with my Adobe Reader. I can easily open the file by just double-clicking the file name, but not by code, so the reader is operating correctly. What is the proper code syntax to open, say, "TheFile.pdf", in the path "ThePath"? Thanks for your time. Otto |
#8
![]()
Posted to microsoft.public.excel.programming
|
|||
|
|||
![]()
This also worked, but assumes Acrobat reader is installed.
Sub efg() Set myShell = CreateObject("WScript.Shell") Filename = "C:\Army_Ex_300_Gde_11-03.pdf" myShell.Run ("AcroRd32.exe " & Filename) End Sub -- Regards, Tom Ogilvy "Otto Moehrbach" wrote: Tom Thanks for your help but it's not working. I ran the following macro to make sure my path and file name are correct. I get "True": Sub TestFileExists() Dim bFileExists As Boolean Dim rsFullPath As String rsFullPath = "C:\LettersForms/Ops Manuals\C1 Ops Manual.pdf" bFileExists = Len(Dir$(rsFullPath)) MsgBox bFileExists End Sub I am running the following and I get a "File not found" error. Your help is greatly appreciated. Otto Sub OttoMacroC1() OpenExcelFilepdf ("C1") End Sub Sub OpenExcelFilepdf(WhichFile As String) ThePath = "C:\LettersForms\Ops Manuals\" TheFile = WhichFile & " Ops Manual.pdf" Shell "Start.exe """ & ThePath & TheFile & """" End Sub "Tom Ogilvy" wrote in message ... Yes, it appears you did misread it: Sub OpenExcelFilepdf(WhichFile As String) ThePath = "C:\LettersForms\Ops Manuals\" TheFile = WhichFile & " Ops Manual.pdf" Shell "Start.exe """ & ThePath & TheFile & """" End Sub Note the space after Start.exe and the additional quotes. Demo'd from the immediate window: ThePath = "C:\LettersForms\Ops Manuals\" Whichfile = "C1" TheFile = WhichFile & " Ops Manual.pdf" ? "Start.exe """ & ThePath & TheFile & """" Start.exe "C:\LettersForms\Ops Manuals\C1 Ops Manual.pdf" shows you want the argument passed to Shell looks like. If you still have problems, you might need to put single quotes in so it ends up being Start.exe "'C:\LettersForms\Ops Manuals\C1 Ops Manual.pdf'" because of the spaces in the names. However, the example I posted has spaces in the path and it worked, so I think yours will work without single quotes as well. -- Regards, Tom Ogilvy -- Regards, Tom Ogilvy -- regards, Tom Ogilvy "Otto Moehrbach" wrote: Tom I think I am misreading what you wrote. Here is what I have written from what you said. I get an error that the file is not found. Sub OttoMacroC1() OpenExcelFilepdf ("C1") End Sub Sub OpenExcelFilepdf(WhichFile As String) ThePath = "C:\LettersForms\Ops Manuals\" TheFile = WhichFile & " Ops Manual.pdf" Shell "Start.exe" & ThePath & TheFile End Sub There is a file named "C1 Ops Manual.pdf" in the cited path. Thanks for your help with this. Otto "Tom Ogilvy" wrote in message ... Private Sub CommandButton1_Click() Shell "Start.exe ""D:\My Documents\sm569_Jan2001\tute6.pdf""" End Sub -- Regards, Tom Ogilvy "Otto Moehrbach" wrote: Excel XP & Win XP I'm trying to get the code for opening a pdf file with my Adobe Reader. I can easily open the file by just double-clicking the file name, but not by code, so the reader is operating correctly. What is the proper code syntax to open, say, "TheFile.pdf", in the path "ThePath"? Thanks for your time. Otto |
#9
![]()
Posted to microsoft.public.excel.programming
|
|||
|
|||
![]()
Chip
This code is way over my head and it works fine. Thank you very much for your time. Otto "Chip Pearson" wrote in message ... Shell "Start.exe ""D:\My Documents\sm569_Jan2001\tute6.pdf""" Start.exe isn't available on all platforms -- at least that has been my experience on Windows XP Pro and Vista. For example, I don't have it here on my laptop with Windows Vista Ultimate (Shell errors with "53 - File Not Found"). Instead, you can use FindExecutable, which will work on any platform, to find the exe file associated with the file and Shell to that exe passing the file name to the exe. Note that the file passed in to FindExecutable must exist. If it doesn't FindExecutable will fail. A result = 32 from FindExecutable indicates success. Change the value of PDFFileName to the fully-qualified name of your PDF file. Public Declare Function FindExecutable Lib "shell32.dll" _ Alias "FindExecutableA" ( _ ByVal lpFile As String, _ ByVal lpDirectory As String, _ ByVal lpResult As String) As Long Const C_MIN_FINDEXE_SUCCESS_VALUE = 32 Const MAX_PATH = 260 Sub ShellToExe() '''''''''''''''''''''''''''''''''''' ' Shells to the exe associated with ' PDFFileName and opens PDFFileName. '''''''''''''''''''''''''''''''''''' Dim ExeName As String Dim Pos As Integer Dim PDFFileName As String Dim Res As Long ' allocate space in ExeName variable. ExeName = String$(MAX_PATH, vbNullChar) ' CHANGE FILE NAME PDFFileName = "C:\Whatever\FileName.pdf" '<<< File MUST exist If Dir(PDFFileName, vbNormal) = vbNullString Then MsgBox "File: " & PDFFileName & " does not exist." & vbCrLf & _ "'FindExecutable' requires an existing file name." Exit Sub End If ' Get the exe name associated with "pdf". Res = FindExecutable(PDFFileName, vbNullString, ExeName) If Res = C_MIN_FINDEXE_SUCCESS_VALUE Then ' trim off trailing vbNullChar characters Pos = InStr(1, ExeName, vbNullChar, vbBinaryCompare) If Pos Then ExeName = Left(ExeName, Pos - 1) End If Shell Chr(34) & ExeName & Chr(34) & Chr(32) & _ Chr(34) & PDFFileName & Chr(34),vbMaximizedFocus Else MsgBox "Error From FindExecutable: " & CStr(Res) End If End Sub -- Cordially, Chip Pearson Microsoft MVP - Excel Pearson Software Consulting, LLC www.cpearson.com (email on the web site) "Tom Ogilvy" wrote in message ... Private Sub CommandButton1_Click() Shell "Start.exe ""D:\My Documents\sm569_Jan2001\tute6.pdf""" End Sub -- Regards, Tom Ogilvy "Otto Moehrbach" wrote: Excel XP & Win XP I'm trying to get the code for opening a pdf file with my Adobe Reader. I can easily open the file by just double-clicking the file name, but not by code, so the reader is operating correctly. What is the proper code syntax to open, say, "TheFile.pdf", in the path "ThePath"? Thanks for your time. Otto |
#10
![]()
Posted to microsoft.public.excel.programming
|
|||
|
|||
![]()
Thanks for your help Tom. Otto
"Tom Ogilvy" wrote in message ... This also worked, but assumes Acrobat reader is installed. Sub efg() Set myShell = CreateObject("WScript.Shell") Filename = "C:\Army_Ex_300_Gde_11-03.pdf" myShell.Run ("AcroRd32.exe " & Filename) End Sub -- Regards, Tom Ogilvy "Otto Moehrbach" wrote: Tom Thanks for your help but it's not working. I ran the following macro to make sure my path and file name are correct. I get "True": Sub TestFileExists() Dim bFileExists As Boolean Dim rsFullPath As String rsFullPath = "C:\LettersForms/Ops Manuals\C1 Ops Manual.pdf" bFileExists = Len(Dir$(rsFullPath)) MsgBox bFileExists End Sub I am running the following and I get a "File not found" error. Your help is greatly appreciated. Otto Sub OttoMacroC1() OpenExcelFilepdf ("C1") End Sub Sub OpenExcelFilepdf(WhichFile As String) ThePath = "C:\LettersForms\Ops Manuals\" TheFile = WhichFile & " Ops Manual.pdf" Shell "Start.exe """ & ThePath & TheFile & """" End Sub "Tom Ogilvy" wrote in message ... Yes, it appears you did misread it: Sub OpenExcelFilepdf(WhichFile As String) ThePath = "C:\LettersForms\Ops Manuals\" TheFile = WhichFile & " Ops Manual.pdf" Shell "Start.exe """ & ThePath & TheFile & """" End Sub Note the space after Start.exe and the additional quotes. Demo'd from the immediate window: ThePath = "C:\LettersForms\Ops Manuals\" Whichfile = "C1" TheFile = WhichFile & " Ops Manual.pdf" ? "Start.exe """ & ThePath & TheFile & """" Start.exe "C:\LettersForms\Ops Manuals\C1 Ops Manual.pdf" shows you want the argument passed to Shell looks like. If you still have problems, you might need to put single quotes in so it ends up being Start.exe "'C:\LettersForms\Ops Manuals\C1 Ops Manual.pdf'" because of the spaces in the names. However, the example I posted has spaces in the path and it worked, so I think yours will work without single quotes as well. -- Regards, Tom Ogilvy -- Regards, Tom Ogilvy -- regards, Tom Ogilvy "Otto Moehrbach" wrote: Tom I think I am misreading what you wrote. Here is what I have written from what you said. I get an error that the file is not found. Sub OttoMacroC1() OpenExcelFilepdf ("C1") End Sub Sub OpenExcelFilepdf(WhichFile As String) ThePath = "C:\LettersForms\Ops Manuals\" TheFile = WhichFile & " Ops Manual.pdf" Shell "Start.exe" & ThePath & TheFile End Sub There is a file named "C1 Ops Manual.pdf" in the cited path. Thanks for your help with this. Otto "Tom Ogilvy" wrote in message ... Private Sub CommandButton1_Click() Shell "Start.exe ""D:\My Documents\sm569_Jan2001\tute6.pdf""" End Sub -- Regards, Tom Ogilvy "Otto Moehrbach" wrote: Excel XP & Win XP I'm trying to get the code for opening a pdf file with my Adobe Reader. I can easily open the file by just double-clicking the file name, but not by code, so the reader is operating correctly. What is the proper code syntax to open, say, "TheFile.pdf", in the path "ThePath"? Thanks for your time. Otto |
Reply |
Thread Tools | Search this Thread |
Display Modes | |
|
|
![]() |
||||
Thread | Forum | |||
How do I get rid of Adobe Reader icon? | Excel Discussion (Misc queries) | |||
how can you hyper link adobe reader files into excel | Excel Discussion (Misc queries) | |||
Adobe inserting into Excel causing the adobe file to be low dpi | Excel Discussion (Misc queries) | |||
how i can take file from adobe reader and make it read with micr. | Excel Discussion (Misc queries) | |||
Identifying version of Adobe Reader | Excel Programming |