Public Schedule Face-to-Face & Online Instructor-Led Training - View dates & book

saving new worksheet

Forum home » Delegate support and help forum » Microsoft Excel VBA Training and help » Saving a new worksheet

Saving a new worksheet

ResolvedVersion 2003

Daren has attended:
Excel VBA Intro Intermediate course

Saving a new worksheet

The programming below creates a new file name from the information in the active workbook

The file name is created

The correct name is displayed in the save as window

But when the save button is selected the save as window disapears, but the workbook is not saved

Can to tell me what I have missed



Sub SaveReport()

Dim VisitNo As String
Dim SiteName As String
Dim SaveName As String
VisitNo = Sheets("DataSheet").Range("H31").Value
SiteName = Sheets("DataSheet").Range("H40").Value
SaveName = SiteName & "-Service Report-" & Date & "-Visit-" & VisitNo

Worksheets("ReportSheet").Activate

Application.GetSaveAsFilename (SaveName)


End Sub

RE: Saving a new worksheet

Hi Daren,

Thank you for your question.

There were two things I added to make the procedure work:

1. The first problem was the date format as you cannot use the / character when saving a filename.

2. I added a line of code to format the date to ddmmyy.

SaveName = SiteName & "-Service Report-" & Format(Date, "ddmmyy") & "-Visit-" & VisitNo

3. You called the application save as dialogue box to appear but didn't tell excel to save the active workbook.

4. I added ActiveWorkbook.SaveAs Filename:=SaveName

I also added a default location to save the file using the:

ChDir "C:\Users\Simon\Documents"

I hope this answers your question.

Regards

Simon






Tue 23 Jun 2009: Automatically marked as resolved.

 

Training courses

Training information:

Welcome. Please choose your application (eg. Excel) and then post your question.

Our Microsoft Qualified trainers will then respond within 24 hours (working days).

Frequently Asked Questions
What does 'Resolved' mean?

Any suggestions, questions or comments? Please post in the Improve the forum thread.

Excel tip:

Page Break Preview in Excel 2010 (Hint/tip)

If you select View then Workbook Views then Page Break Preview, you will be able to view how your Excel spreadsheet will be split across multiple pages when printed. Even better, you can also drag a page break to a new place. Excel will then scale down your entire worksheet to fit the information you want on the pages you want.

View all Excel hints and tips

Connect with us:

0207 987 3777

Call for assistance

Request Callback

We will call you back

Server loaded in 0.11 secs.