Page 1 of 1

vba copy

Posted: Wed Aug 10, 2022 7:05 am
by sna
#needhelp

Hi Dear!

I need help with the code. I want that relevant tab to be exported in XLSX form as well in the relevant folder. I have tried different codes myself but unfortunately couldn't be succeeded.

I shall be grateful for the help. Thanks.

Code: Select all

Sub nn()
Dim wb As Workbook
On Error Goto Handler
Application.ScreenUpdating=False
Application.DisplayAlerts=False
Const X As String= "C:\ABC" & Sheets(1).Range("h3").Value &"_"&Format(Now,"HHMMSS")
Set wb=Workbooks.Add
Sheets("Invoice").Copy after:=wb.Sheets(wb.Sheets.Count)
wb.Sheets(1).Delete
wb.SaveAs Filename:=X &".xlsx'" ,Fileformat:=51
Sheets("invoice"). Activate
wb.Close 
Handler:
Application.ScreenUpdating=True
Application.DisplayAlerts=True
End Sub
Thank you for kind help

Re: vba copy

Posted: Wed Aug 10, 2022 1:22 pm
by puriwutpokin
Revised this

Code: Select all

Sub nn()
Dim wb As Workbook
Dim X As String
On Error GoTo Handler
Application.ScreenUpdating = False
Application.DisplayAlerts = False
X = "C:\ABC" & Sheets(1).[H3] & "_" & Format(Now, "HHMMSS") & ".xlsx"
Set wb = Workbooks.Add
ThisWorkbook.Sheets("Invoice").Copy after:=wb.Sheets(wb.Sheets.Count)
wb.Sheets(1).Delete
wb.SaveAs Filename:=X, FileFormat:=51
Sheets("invoice").Activate
wb.Close
Handler:
Application.ScreenUpdating = True
Application.DisplayAlerts = True
End Sub

Re: vba copy

Posted: Thu Aug 11, 2022 6:11 am
by sna
Thank you