Formulir Kontak

Nama

Email *

Pesan *

Cari Blog Ini

Excel Vba Save Active Worksheet Name

```html

How to Save Only the Active Worksheet in Excel VBA

Problem

You are using VBA to save an Excel workbook, but it saves the entire workbook, including all worksheets. You only want to save the active worksheet.

Solution

You can use the following VBA code to save only the active worksheet: ```vba Sub SaveActiveWorksheet() Dim shName As String Dim ws As Worksheet shName = ActiveSheet.Name ActiveSheet.Copy ActiveSheet.Name = shName ActiveWorkbook.SaveAs Filename:="C:\path\to\file.xlsx" End Sub ```

Explanation

The code first gets the name of the active worksheet and stores it in the variable `shName`. Then, it copies the active worksheet and assigns the `shName` to the new worksheet. Finally, it saves the new workbook as a new file.

Additional Notes

* You can change the file path in the `SaveAs` method to save the file to a different location. * You can also use the `Save` method to save the workbook without creating a new file. However, this will overwrite the existing workbook. * If you want to save the active worksheet as a PDF, you can use the `ExportAsFixedFormat` method. I hope this helps! Let me know if you have any other questions. ```


Komentar