VBA: Input box and save

mjs1982

New Member
Joined
Jan 23, 2013
Messages
9
At the time a file is opened, I'd like an input box to pop up that states, "This Tract Is:" and the editable text in the input box (the white box) is referenced from a cell in the just opened workbook - always cell A1. Then the user can edit any text he needs to, press "okay" and the file will automatically save using what the user typed (or edited from the A1 cell reference) in the input box as the file save as name, after "okay" is pressed. I believe I know the VBA to save, but if anyone sees any errors, feel free to comment.


Private Sub SaveWorkbookAsNewFile(NewFileName As String) Dim ActSheet As Worksheet Dim ActBook As Workbook Dim CurrentFile As String Dim NewFileType As String Dim NewFile As String Application.ScreenUpdating = False ' Prevents screen refreshing. CurrentFile = ThisWorkbook.FullName NewFileType = "Excel Files 1997-2003 (*.xls), *.xls," & _ "Excel Files 2007 (*.xlsx), *.xlsx," & _ "All files (*.*), *.*" NewFile = Application.GetSaveAsFilename( _ InitialFileName:=NewFileName, _ fileFilter:=NewFileType) If NewFile <> "" And NewFile <> "False" Then ActiveWorkbook.SaveAs Filename:= NewFile, _ FileFormat:=xlNormal, _ Password:="", _ WriteResPassword:="", _ ReadOnlyRecommended:=False, _ CreateBackup:=False Set ActBook = ActiveWorkbook Workbooks.Open CurrentFile ActBook.Close End If Application.ScreenUpdating = TrueEnd Sub

***Uh, that didn't paste how I thought it would...
 
Last edited:

Excel Facts

Round to nearest half hour?
Use =MROUND(A2,"0:30") to round to nearest half hour. Use =CEILING(A2,"0:30") to round to next half hour.

Forum statistics

Threads
1,216,963
Messages
6,133,764
Members
449,829
Latest member
dcedano

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