need macro from button to open selectable file

D

dillon26

i have a program that will export data to excel (text only). i am trying to
make a file which contains only a button that launches a macro that begins by
allowing the user to select the file to which they exported the data, then
the macro will change the formatting of the selected file.

i have the macro saved in my personal macro workbook that does the
formatting, and i can create the button on a new page, but i do not know how
to get from pressing the button to opening a user selected file and then
running the formatting.

thanks in advance. dillon
 
P

Per Jessen

Hi

If the file you want to select and use your formatting on, this should do
it:

Private Sub CommandButton1_Click()

MyFileName = Application.GetOpenFilename
Set wb1 = Workbooks.Open(MyFileName)
wb1.Activate
Call MyFormatSub
wb1.Save
wb1.Close
Set wb1 = Nothing
End Sub

Hopes this helps.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top