Excel Macro to Save Sheets As xlsx

mare23

New Member
Joined
Oct 28, 2020
Messages
22
Office Version
  1. 365
Platform
  1. Windows
Hi all,

I am new to the VBA and Macro world, but I have been trying for a week to figure out a specific code. I need to create a macro that will take that Purchase order template once filled out and save it as an Xlsx file. I have code for PDF below and I need same fo xlsx. Is it possible to save excel for specific columns/rows as in the code below? And also when I click the SAVE button let it save my file without opening it


'Save Invoice as PDF

On Error Resume Next

Sheet2.Range("B2:T65").ExportAsFixedFormat xlTypePDF, Filename:= _
"C:\invoice\" & Sheet2.Range("R4").Value, Openafterpublish:=False
End Sub

thx
Mare
 

Excel Facts

Can you AutoAverage in Excel?
There is a drop-down next to the AutoSum symbol. Open the drop-down to choose AVERAGE, COUNT, MAX, or MIN
See if this will do what you want.

VBA Code:
Sub t()
Dim sh As Worksheet, fPath
fPath = ThisWorkbook.Path
With ThisWorkbook
    Set sh = .Sheets.Add
    Sheet2.Range("B2:T65").Copy sh.Range("B2")
    sh.Copy
    ActiveWorkbook.SaveAs fPath & "\" & Sheet2.Range("R4").Value & ".xlsx", 51
    ActiveWorkbook.Close False
    Application.DisplayAlerts = False
    sh.Delete
    Application.DisplayAlerts = True
End With
End Sub
 
Upvote 0
Great, that’s it but I want to save this xlsx in "C:\invoice\"
 
Upvote 0
VBA Code:
fPath = ThisWorkbook.Path

Change to:

VBA Code:
fPath = "C:\Invoice"
 
Upvote 0
One more question how to Use PasteSpecial Method to Copy Range and Paste in Another Sheet with Formatting and Column Widths. I need same size as original, without Gridlines and with 70% zoom
 
Upvote 0
One more question how to Use PasteSpecial Method to Copy Range and Paste in Another Sheet with Formatting and Column Widths. I need same size as original, without Gridlines and with 70% zoom
example:
Sheet1.Range("A2:F20").Copy
VBA Code:
With Sheet2
    .Range("A2").PasteSpecial xlPasteColumnWidths
    .Range("A2").PasteSpecial. xlPasteValuesAndNumberFormats
End With

For reference: XlPasteType enumeration (Excel)
 
Upvote 0
Sorry I didn't mean another sheet in the same workbook, I mean in new workbook. I need Copy/paste same as I have in original workbook without gridlines and with same size and merge rows/columns...
 
Upvote 0
Sorry I didn't mean another sheet in the same workbook, I mean in new workbook. I need Copy/paste same as I have in original workbook without gridlines and with same size and merge rows/columns...
It is the same principle. You just and in the workbook reference in front of the sheet reference.

VBA Code:
Workbooks(2).Sheets(2).PasteSpecial xlPasteColumnWidths
 
Upvote 0

Forum statistics

Threads
1,214,591
Messages
6,120,424
Members
448,961
Latest member
nzskater

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