If this is your first visit, be sure to check out the FAQ by clicking the link above. You may have to register before you can post: click the register link above to proceed. To start viewing messages, select the forum that you want to visit from the selection below.

 
Go Back  dBforums > PC based Database Applications > Microsoft Excel > VBA Excel macro

Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1 (permalink)  
Old 06-30-04, 08:42
ioclio ioclio is offline
Registered User
 
Join Date: Jun 2004
Location: Italy
Posts: 15
VBA Excel macro

Hi,

I developed an Excel macro using XP (Office 10.0 Object Library).
Now the users are asking to run it with previous Excel versions (Excel 95, 97).
Now the problem is that I used Application.FileDialog(msoFileDialogFilePicker) to browse for files and I don't know how this could be replaced with older libraries (actually I could use a simple InputBox, but then I discovered this forum... ).

Thanks in advance
FatherXmas
Reply With Quote
  #2 (permalink)  
Old 06-30-04, 11:36
DavidCoutts DavidCoutts is offline
Registered User
 
Join Date: Jan 2004
Location: Aberdeen, Scotland
Posts: 1,067
HI

If its for opening or saving files etc
I know for XL97 you can use

Application.GetOpenFilename

which return the Path and Name of the selected item and you can use
Store it to a variable
the workbookname you can get from using Left and Right Functions
Code:
    myFile = Application.GetOpenFilename
    Filename = Right(myFile, Len(myFile) - InStrRev(myFile, "\"))
    Filename = Left(Filename, InStr(Filename, ".") - 1)
or using ActiveWorkbook.Name if you open it.

the equivalent for the Save Dialog is
Application.GetSaveAsFilename

Im Afraid i dont know about XL95
Hope this Helps

David
Reply With Quote
  #3 (permalink)  
Old 06-30-04, 11:57
ioclio ioclio is offline
Registered User
 
Join Date: Jun 2004
Location: Italy
Posts: 15
Hi David,
thanks for help,that's actually a good hint. The fact is that I should allow multiple selections...something like:

Dim FileDlg As FileDialog
Set FileDlg = Application.FileDialog(msoFileDialogFilePicker)
Do
FileDlg.Title = "Select which files to use"
FileDlg.InitialView = msoFileDialogViewList
FileDlg.InitialFileName = "C:\"
FileDlg.Show
NumberOfSelections = FileDlg.SelectedItems.Count

If NumberOfSelections = 0 Then
Selection = MsgBox("No file selected." & vbCrLf & _
"Stop?", vbYesNo)
If Selection = vbYes Then
Exit Sub
End If
End If
Loop While (NumberOfSelections = 0)

I think Application.GetOpenFilename let you select only one file...
Reply With Quote
  #4 (permalink)  
Old 06-30-04, 15:55
DavidCoutts DavidCoutts is offline
Registered User
 
Join Date: Jan 2004
Location: Aberdeen, Scotland
Posts: 1,067
Hi

you can actually select multiplefiles with getopenfilename

something like
Code:
    Dim aryOpenFiles As Variant, i As Integer
    aryOpenFiles = Application.GetOpenFilename(MultiSelect:=True)
    If IsArray(aryOpenFiles) Then
        For i = LBound(aryOpenFiles) To UBound(aryOpenFiles)
            'insert your code here
            MsgBox aryOpenFiles(i)
        Next i
    End If
i threw in a messagebox but put your own code in there

HTH

David
Reply With Quote
  #5 (permalink)  
Old 07-01-04, 03:18
ioclio ioclio is offline
Registered User
 
Join Date: Jun 2004
Location: Italy
Posts: 15
Quote:
Originally Posted by DavidCoutts

HTH

David
It does. Thanks David
Reply With Quote
  #6 (permalink)  
Old 07-01-04, 03:47
ioclio ioclio is offline
Registered User
 
Join Date: Jun 2004
Location: Italy
Posts: 15
Oopss...just another question:

how can I dinamically let the user browse for a directory starting from a defined path?
I mean...just suppose someone opens a.xls in C:\whoknows\.
How can I make the browser starting from C:\whoknows\ ?

Thanks again
Reply With Quote
  #7 (permalink)  
Old 07-01-04, 10:26
DavidCoutts DavidCoutts is offline
Registered User
 
Join Date: Jan 2004
Location: Aberdeen, Scotland
Posts: 1,067
Before you make a call to the application.getopenfilename
just change the directory to what you want,
I they have opened a previous example use the LEFT function to get the Path store it as a variable(myFilePath) then use

ChDir MyFilePath

or just force them to some place like

ChDir "C:\WhoKnows"
Reply With Quote
  #8 (permalink)  
Old 07-01-04, 11:02
ioclio ioclio is offline
Registered User
 
Join Date: Jun 2004
Location: Italy
Posts: 15
Ok, it works fine.
Thanks for your help David.
Reply With Quote
Reply

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

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