Write Code to save an Excel File

Posted on 2002-04-10
Last Modified: 2010-05-02
How do I write code at the end of my macro that will automatically save a file after the macro does its task? This file will be located on each persons desktop for easy access.
After the macro assigns a PO number I want the file saved automatically (written in the code) and after each user fill out their order form it will be up to them to do a manual "Save As" to their proper folder.

here is my macro for further reference.....
Public Sub GetNewJobNumber()
Dim strJob As String
 strJob = InputBox("Enter job number")
 Worksheets("Access & Couplers").Range("I9") = strJob & "-" _ & Worksheets("PONumber").Range("A1")
 End Sub
Question by:He4Giv

Expert Comment

ID: 6932568
I think something like this should work

Public Sub GetNewJobNumber()

Dim strJob As String

strJob = InputBox("Enter job number")
Worksheets("Access & Couplers").Range("I9") = strJob & "-" _ & Worksheets("PONumber").Range("A1")

ChDir "C:\WINDOWS\Desktop"
    ActiveWorkbook.SaveAs Filename:="temp.xls", FileFormat:= _
        xlNormal, Password:="", WriteResPassword:="", ReadOnlyRecommended:=False _
        , CreateBackup:=False
End Sub


Accepted Solution

kcm76 earned 50 total points
ID: 6932586
How about just **Worsheets(X).save**


Author Comment

ID: 6932764
Yours didnt work but was close so I checked VB help and found the syntax to be....


This saved the file for me


Featured Post

Announcing the Most Valuable Experts of 2016

MVEs are more concerned with the satisfaction of those they help than with the considerable points they can earn. They are the types of people you feel privileged to call colleagues. Join us in honoring this amazing group of Experts.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
Problem to skip loop 6 62
Computer crashes, following error message in event manager 5 234
Copy a row 12 63
Advice in Xamarin 21 96
I’ve seen a number of people looking for examples of how to access web services from VB6.  I’ve been using a test harness I built in VB6 (using many resources I found online) that I use for small projects to work out how to communicate with web serv…
You can of course define an array to hold data that is of a particular type like an array of Strings to hold customer names or an array of Doubles to hold customer sales, but what do you do if you want to coordinate that data? This article describes…
As developers, we are not limited to the functions provided by the VBA language. In addition, we can call the functions that are part of the Windows operating system. These functions are part of the Windows API (Application Programming Interface). U…
Get people started with the utilization of class modules. Class modules can be a powerful tool in Microsoft Access. They allow you to create self-contained objects that encapsulate functionality. They can easily hide the complexity of a process from…

789 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question