Home |
Search |
Today's Posts |
#1
Posted to microsoft.public.excel.programming
|
|||
|
|||
Open a .pdf file using vba in excel 2003
Hi everyone,
I have a sub that searches for files in a directory and adds them to the list box. I want the user to be able to click on a filename inside the listbox and open it (pdf file). Can someone give me some suggestions on how to do this? thanks for your help. here is what i got: Dim fs As Object Dim I As Integer 'Dim Flange_sname(100) As String ' Set fs = Application.FileSearch With fs .LookIn = "X:\Omar\Finished_Flanges" .SearchSubFolders = False .Filename = Flange_sname .FileType = ".pdf" If .Execute() 0 Then 'MsgBox "There were " & .FoundFiles.Count & " file(s) found." For I = 1 To .FoundFiles.Count 'MsgBox .FoundFiles(I) Lbx_file_names.AddItem .FoundFiles(I) Next I Else 'MsgBox "There were no files found." End If End With this returns = X:\Omar\Finished_Flanges\14_600_RTJ_WN_S40.pdf |
#2
Posted to microsoft.public.excel.programming
|
|||
|
|||
Open a .pdf file using vba in excel 2003
Try this. The last I knew, Filesearch was not supported in 2007.
Option Explicit Sub Test() Dim myFolder As String Dim myFile As String Dim myCount as long myFolder = "X:\Omar\Finished_Flanges\" myFile = Dir(myFolder & "*.pdf") myCount = 0 If myFile < "" Then Do myCount = myCount + 1 Lbx_file_names.AddItem myFile myFile = Dir() Loop While myFile < "" end if if myCount = 0 then MsgBox ("There were no files found") else Msgbox("There were " & mycount & " files found.") End If HTH, Barb Reinhardt "Omar" wrote: Hi everyone, I have a sub that searches for files in a directory and adds them to the list box. I want the user to be able to click on a filename inside the listbox and open it (pdf file). Can someone give me some suggestions on how to do this? thanks for your help. here is what i got: Dim fs As Object Dim I As Integer 'Dim Flange_sname(100) As String ' Set fs = Application.FileSearch With fs .LookIn = "X:\Omar\Finished_Flanges" .SearchSubFolders = False .Filename = Flange_sname .FileType = ".pdf" If .Execute() 0 Then 'MsgBox "There were " & .FoundFiles.Count & " file(s) found." For I = 1 To .FoundFiles.Count 'MsgBox .FoundFiles(I) Lbx_file_names.AddItem .FoundFiles(I) Next I Else 'MsgBox "There were no files found." End If End With this returns = X:\Omar\Finished_Flanges\14_600_RTJ_WN_S40.pdf |
#3
Posted to microsoft.public.excel.programming
|
|||
|
|||
Open a .pdf file using vba in excel 2003
Barb,
Thanks for your help. How do I open the file thought? Your code displays the file name in the listbox rather that the full path. I like your solution better, but Is there a way the user can double click a item from the list using your code and have that file open? Thanks again, Omar |
#4
Posted to microsoft.public.excel.programming
|
|||
|
|||
Open a .pdf file using vba in excel 2003
I'm going to assume that the List is in Cell A1 of a worksheet. Modify and
put this in your Worksheet_Change event for the worksheet. This should get you started. Option Explicit Private Sub Worksheet_Change(ByVal Target As Range) Dim myURL As String Dim myIE As Object Set myIE = CreateObject("InternetExplorer.Application") Const READYSTATE_COMPLETE As Long = 4 If Not Intersect(Target, Me.Range("A1")) Is Nothing Then myURL = "X:\Omar\Finished_Flanges\" & Target.Text Debug.Print myURL On Error Resume Next myIE.navigate myURL myIE.Visible = True On Error GoTo 0 Do While myIE.Busy Or myIE.readyState < READYSTATE_COMPLETE DoEvents Loop End If End Sub "Omar" wrote: Hi everyone, I have a sub that searches for files in a directory and adds them to the list box. I want the user to be able to click on a filename inside the listbox and open it (pdf file). Can someone give me some suggestions on how to do this? thanks for your help. here is what i got: Dim fs As Object Dim I As Integer 'Dim Flange_sname(100) As String ' Set fs = Application.FileSearch With fs .LookIn = "X:\Omar\Finished_Flanges" .SearchSubFolders = False .Filename = Flange_sname .FileType = ".pdf" If .Execute() 0 Then 'MsgBox "There were " & .FoundFiles.Count & " file(s) found." For I = 1 To .FoundFiles.Count 'MsgBox .FoundFiles(I) Lbx_file_names.AddItem .FoundFiles(I) Next I Else 'MsgBox "There were no files found." End If End With this returns = X:\Omar\Finished_Flanges\14_600_RTJ_WN_S40.pdf |
#5
Posted to microsoft.public.excel.programming
|
|||
|
|||
Open a .pdf file using vba in excel 2003
This list is only in a listbox? Is this only possible to do this from a
worksheet. I will try out your code. thanks |
#6
Posted to microsoft.public.excel.programming
|
|||
|
|||
Open a .pdf file using vba in excel 2003
Works great, thanks for helping a noob! lol
|
#7
Posted to microsoft.public.excel.programming
|
|||
|
|||
Open a .pdf file using vba in excel 2003
Adobe acrobat has a activex plugin. If you have Adobde acrobat, then you
already have the plugin. You can add that to your toolbox. If you go to add additional controls, you can add the plugin. Once it is in your toolbox, you can drag it onto a userform. When the user clicks on a a list item, a userform with the adodbe plugin can open and show the pdf. Tony "Omar" wrote: Barb, Thanks for your help. How do I open the file thought? Your code displays the file name in the listbox rather that the full path. I like your solution better, but Is there a way the user can double click a item from the list using your code and have that file open? Thanks again, Omar |
Reply |
Thread Tools | Search this Thread |
Display Modes | |
|
|
Similar Threads | ||||
Thread | Forum | |||
How can I open a .pxl file in Excel 2003? | Excel Discussion (Misc queries) | |||
Saved *.csv file gives SYLK file type warning upon Excel 2003 open | Excel Discussion (Misc queries) | |||
excel 2003 saved file will not open without a blank workbook open | Excel Discussion (Misc queries) | |||
I have Excel 2003 and want to open an old WB2 file How do i do it | Excel Discussion (Misc queries) | |||
Excel 2003 Workbooks.Open with CorruptLoad=xlRepairFile fails on Excel 5.0/95 file due to Chart, with Error 1004 Method 'Open' of object 'Workbooks' failed | Excel Programming |