Is there a way to find all workbooks in a computer using excel, and then pick which one to add a code to it?
Is there a way to find all workbooks in a computer using excel, and then pick which one to add a code to it?
and once picked, it runs the code to the selected workbook?
and once picked, it runs the code to the selected workbook?
Do you mean you want to add code to a workbook, or run code that manipulates a particular workbook?
Regards,
Rory
Microsoft MVP - Excel
I need a code that will let me choose a workbook, then when chosen, I can run a code I already have on it.Originally Posted by rory
If you add the code to Workbook_Open in that workbook, it will run automatically when you open it.
You can select a file using GetOpenFilename, look it up in Help to see how to use it.
____________________________________________
Nihil simul inventum est et perfectum
Abusus non tollit usum
Last night I dreamed of a small consolation enjoyed only by the blind: Nobody knows the trouble I've not seen!
James Thurber
Well you can easily use GetOpenFilename to allow the user to choose a workbook.
Then you can open it, create a reference to it and use that reference in the code.
By the way your title and original post were rather confusing, I think anyway.
I actually thought you wanted to select a workbook and then use code to create code in the selected workbook.
Is there a way for the code to be run as soon as the user selects the workbook from GetOpenFilename?Originally Posted by Norie
Not really, you would probably still need to open the workbook.
Is that a problem?
PS What is the code actually doing?
Yeah that is a problem, I need to hypothetically think the user has no Excel VBA knowledge at all. The code just creates a toolbar that hides/unhides columns in the spreadsheet.Originally Posted by Norie
Can I get instructions on doing this?Originally Posted by Norie
Sure, lookup up GetOpenFilename and Set in VBA help.
____________________________________________
Nihil simul inventum est et perfectum
Abusus non tollit usum
Last night I dreamed of a small consolation enjoyed only by the blind: Nobody knows the trouble I've not seen!
James Thurber
I got this far:
Originally Posted by xldhow do I make it open the file when I select it?Sub GetImportFilename() Dim Finfo As String Dim FilterIndex As Integer Dim Title As String Dim Filename As Variant ' Set up list of file filters Finfo = "Text Files (*.txt),*.txt," & _ "Lotus Files (*.prn),*.prn," & _ "Comma Separated Filed (*.csv),*.csv," & _ "ASCII FILES (*.asc),*.asc," & _ "All Files (*.*),*.*" ' Display *.* by default FilterIndex = 5 ' Set the dialog box caption Title = "Select a File to Import" ' Get the filename Filename = Application.GetOpenFilename(Finfo, FilterIndex, File) ' Handel return info dialog box If Filename = False Then MsgBox "No file was selected." Else MsgBox "You selected " & Filename End If End Sub
[vba]
Sub GetImportFilename()
Dim Finfo As String
Dim FilterIndex As Integer
Dim Title As String
Dim Filename As Variant
Dim WB As Workbook
' Set up list of file filters
Finfo = "Text Files (*.txt),*.txt," & _
"Lotus Files (*.prn),*.prn," & _
"Comma Separated Filed (*.csv),*.csv," & _
"ASCII FILES (*.asc),*.asc," & _
"All Files (*.*),*.*"
' Display *.* by default
FilterIndex = 5
' Set the dialog box caption
Title = "Select a File to Import"
' Get the filename
Filename = Application.GetOpenFilename(Finfo, FilterIndex, file)
' Handel return info dialog box
If Filename = False Then
Exit Sub
Else
Set WB = Workbooks.Open(Filename)
End If
End Sub
[/vba]
____________________________________________
Nihil simul inventum est et perfectum
Abusus non tollit usum
Last night I dreamed of a small consolation enjoyed only by the blind: Nobody knows the trouble I've not seen!
James Thurber