Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chriss Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Excel VBA Function OutPutTo 1

Status
Not open for further replies.

maeling

Technical User
Sep 23, 2002
109
GB
In MS Access there is a function OutPutTo which enables you to output a databse object such as a table or query as a file such as Excel, to a designated location c:\output.xls.
Is this function available in Excel ?
I would like to create a macro behind a button on a worksheet that will output the slected sheet to a file ? Is this possible ?
 
Not directly. The following code would create a copy of a worksheet and then save it

Code:
sheets("SheetName").copy
activeworkbook.saveas "File Path & Name.xls"


Rgds, Geoff

We could learn a lot from crayons. Some are sharp, some are pretty and some are dull. Some have weird names and all are different colours but they all live in the same box.

Please read FAQ222-2244 before you ask a question
 
Hello again,
I copied and pasted both lines of your code directly into a macro I was editing. After saving it I attempted to run it. I got the following message.
"run time error 9"
"subscript out of range"
Line one was hilighted yellow.
I removed the line and the second line worked fine but used the active sheet as opposed to the selected one...I think.
 
You need to change SheetName to the actual name of the sheet you are wanting to copy to a new workbook.

If that sheet is the ACTIVE sheet at the time then

Activesheet.copy
activeworkbook.saveas "File Path & Name.xls"

will work - otherwise you will have to specify the sheet NAME to copy

Rgds, Geoff

We could learn a lot from crayons. Some are sharp, some are pretty and some are dull. Some have weird names and all are different colours but they all live in the same box.

Please read FAQ222-2244 before you ask a question
 
Hello,
yes I had changed the sheet name but still got the error ?? However it will always be the active sheet so yoour second suggestions works perfectly.

Thanks
 
no probs - hope you get somewhere with the lookup query !

Rgds, Geoff

We could learn a lot from crayons. Some are sharp, some are pretty and some are dull. Some have weird names and all are different colours but they all live in the same box.

Please read FAQ222-2244 before you ask a question
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top