Code Help - Automation

Joneye

Well-known Member
Joined
May 28, 2010
Messages
785
Office Version
  1. 365
  2. 2019
Platform
  1. Windows
  2. MacOS
I have a work book with many tabs, I wish just for one tab to be exported with the data to a Named folder.

Also this process will take place a few times a week so if the above is possible the exported work book must not conflict with the last.

Is this possible?
 

Excel Facts

Remove leading & trailing spaces
Save as CSV to remove all leading and trailing spaces. It is faster than using TRIM().
Try like this

Code:
Sub SaveSheet()
Sheets("Sheet1").Copy
With ActiveWorkbook
    .SaveAs Filename:="C:\test\Copy " & Format(Date, "ddmmyyyy") & ".xls"
    .Close
End With
End Sub
 
Upvote 0
VOG, I have little experience in VBA, I asume i alt + F11 then click on the relevant tab and insert my code?

Can I then assign this to a button? - (either command or or button)

Many thanks in advance.
 
Upvote 0
Press ALT + F11 to open the Visual Basic Editor, select Module from the Insert menu and paste in the code. Change the bits in red to suit:

Rich (BB code):
Sub SaveSheet()
Sheets("Sheet1").Copy
With ActiveWorkbook
    .SaveAs Filename:="C:\test\Copy " & Format(Date, "ddmmyyyy") & ".xls"
    .Close
End With
End Sub
Press ALT + Q to close the code window. Add a button from the Forms toolbar and when prompted assign it to SaveSheet.
 
Upvote 0
That is AWESOME VOG - Just made my day :)
 
Upvote 0
Quick question this part of the code & Format(Date, "ddmmyyyy") & ".xls"

Can i include time also so that if im saving every now and again it does not cause a confliction?
 
Upvote 0
Try

Rich (BB code):
Sub SaveSheet()
Sheets("Sheet1").Copy
With ActiveWorkbook
    .SaveAs Filename:="C:\test\Copy " & Format(Now, "ddmmyyyy hhmmss") & ".xls"
    .Close
End With
End Sub
 
Upvote 0
VOG - thanks for the pace and speed of your help... Again BRILLIANT
 
Upvote 0
VOg using the code supplied before, can I export an additional tab?

Plus can I clean the data that im exporting just to copy the raw data not the links its attached to in the sheet?
 
Upvote 0
Try like this

Code:
Sub SaveSheet()
Dim ws As Worksheet
Sheets(Array("Sheet1", "Sheet2")).Copy
For Each ws In ActiveWorkbook
    With ws.UsedRange
        .Value = .Value
    End With
Next ws
With ActiveWorkbook
    .SaveAs Filename:="C:\test\Copy " & Format(Now, "ddmmyyyy hhmmss") & ".xls"
    .Close
End With
End Sub
 
Upvote 0

Forum statistics

Threads
1,224,585
Messages
6,179,703
Members
452,938
Latest member
babeneker

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