Answer the question
In order to leave comments, you need to log in
How to save file keeping page title in Excel using VBA?
Using the following code in VBA, I split the entire file into n files with the specified number of lines. The problem is that all generated files do not accept the page name of the source file. Please help, how can I rewrite the script so that all new files have the same page name as the original file?
Option Explicit
Option Base 1
Sub Border_Limit()
Dim Limit As Integer, Count As Integer, SaveDir As String, SetTitle As Boolean
Count = 1: Limit = 1000
SetTitle = True
SaveDir = ThisWorkbook.Path
While Not IsEmpty(Cells(IIf(SetTitle, 2, 1), 1))
Rows("1:" & Limit).Copy
Workbooks.Add xlWBATWorksheet
ActiveSheet.Paste: Cells(1, 1).Select
ActiveWorkbook.SaveAs Filename:=SaveDir & "\file_" & Count & ".xlsx", _
FileFormat:=xlOpenXMLWorkbook
ActiveWindow.Close
Rows(IIf(SetTitle, 2, 1) & ":" & Limit).Delete Shift:=xlUp
Count = Count + 1
Wend: MsgBox "File separated on " & Count - 1 & " files. "
End Sub
Answer the question
In order to leave comments, you need to log in
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question