VBA instruction for save a sheet and clear the cells

Ider Boucetta

New Member
Joined
Mar 14, 2023
Messages
2
Office Version
  1. 365
  2. 2016
Platform
  1. Windows
Hello Everybody ,
i was trying to create a simple Macro which saves my excel file sheet as a different workbook with a Button and everytime change the name of the file (ex. the first file name is "Test1.xlsx" the second time you click the button the file name is "Test2.xlsx") .
i'm not very experienced on VBA i am self taught and i tried to create this code based on the functions i read on the internet.
this part should save "Sheet1" as .xlsx on the destination that i put into "strName" but it doesn't work and i dont know what is the error.
also if you know how to do it, after saving sheet1 in another file I would like to delete the data in a column of the main file. in my specific case the D:D

VBA Code:
Sub Button_Click()

    Dim strName As String

    Application.DisplayAlerts = False

   
    strName = "V:\0\TEST" + "\TEST.XLSL"
 

    ThisWorkbook.Sheets("Sheet1").Copy
    ActiveWorkbook.SaveAs Filename:=strName, FileFormat:=xlOpenXMLStrictWorkbook, CreateBackup:=True
    
    Application.DisplayAlerts = True

End Sub

I don't know if I was clear and if you also need my file, I'll gladly send it to you.

Thank you for your attention
 

Excel Facts

When they said...
When they said you are going to "Excel at life", they meant you "will be doing Excel your whole life".
Hello Everybody ,
i was trying to create a simple Macro which saves my excel file sheet as a different workbook with a Button and everytime change the name of the file (ex. the first file name is "Test1.xlsx" the second time you click the button the file name is "Test2.xlsx") .
i'm not very experienced on VBA i am self taught and i tried to create this code based on the functions i read on the internet.
this part should save "Sheet1" as .xlsx on the destination that i put into "strName" but it doesn't work and i dont know what is the error.
also if you know how to do it, after saving sheet1 in another file I would like to delete the data in a column of the main file. in my specific case the D:D

VBA Code:
Sub Button_Click()

    Dim strName As String

    Application.DisplayAlerts = False

  
    strName = "V:\0\TEST" + "\TEST.XLSL"
 

    ThisWorkbook.Sheets("Sheet1").Copy
    ActiveWorkbook.SaveAs Filename:=strName, FileFormat:=xlOpenXMLStrictWorkbook, CreateBackup:=True
   
    Application.DisplayAlerts = True

End Sub

I don't know if I was clear and if you also need my file, I'll gladly send it to you.

Thank you for your attention
Correction when i click the button a file name TEST. xlsl is created on the directory i chose so that part works, i still dont know how to clear the column after the file has been created
 
Upvote 0

Forum statistics

Threads
1,214,822
Messages
6,121,765
Members
449,049
Latest member
greyangel23

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