Create new workbook, save using input box

Sphinx404

Board Regular
Joined
May 2, 2015
Messages
186
Office Version
  1. 365
Platform
  1. Windows
I've read a lot of the different threads on this forum concerning adding a new workbook but I cannot seem to get the macro to work the way it needs to... the code below doesn't work, it's not the proper syntax but it gives you an idea of what I'm trying to do:

1. add new Workbook
2. save new Workbook
3. add input box so the user can designate the filename
4. designate the proper filepath
5. save file to filepath


Code:
[COLOR=#323232][FONT=Arial]Sub Macro2()[/FONT][/COLOR]
[COLOR=#323232][FONT=Arial]Dim Wk As Workbook
Dim fname As String[/FONT][/COLOR]
[COLOR=#323232][FONT=Arial]Set Wk = Workbooks.Add
Application.DisplayAlerts = False
fname = InputBox(“What is the filename?”)
Wk.SaveAs Filename:=”C:\” & fname & “.xlsx”
Application.DisplayAlerts = True[/FONT][/COLOR]
[COLOR=#323232][FONT=Arial]End Sub[/FONT][/COLOR]

It seems like a simple task, if anyone could offer their guidance I'd be appreciative. Thanks!
 

Excel Facts

Test for Multiple Conditions in IF?
Use AND(test, test, test, test) or OR(test, test, test, ...) as the logical_test argument of IF.
Why not use the SaveAs dialog box? That way you can select the path with the dialog box tools as well as enter the name and file extension you want.
Code:
Sub Macro2()
Dim Wk As Workbook
Dim fname As String, fPathFile As String
fname = InputBox("Enter the file name to use, including file extension.")
Set Wk = Workbooks.Add
fPathFile = Application.GetSaveAsFilename(fname, "Excel Files (*.xlsx), *.xlsx")
wk.SaveAs fPathFile
End Sub
 
Last edited:
Upvote 0
Why not use the SaveAs dialog box? That way you can select the path with the dialog box tools as well as enter the name and file extension you want.
Code:
Sub Macro2()
Dim Wk As Workbook
Dim fname As String, fPathFile As String
fname = InputBox("Enter the file name to use, including file extension.")
Set Wk = Workbooks.Add
fPathFile = Application.GetSaveAsFilename(fname, "Excel Files (*.xlsx), *.xlsx")
wk.SaveAs fPathFile
End Sub

Thank you! I decided to give the user the option to select their own filepath rather than designate one, but this gave me the bits and pieces I needed to complete the code. Thanks for your assistance!
 
Upvote 0
Thank you! I decided to give the user the option to select their own filepath rather than designate one, but this gave me the bits and pieces I needed to complete the code. Thanks for your assistance!

You're welcome,
regards, JLG
 
Upvote 0

Forum statistics

Threads
1,223,910
Messages
6,175,318
Members
452,634
Latest member
cpostell

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top