matrix26
Board Regular
- Joined
- Dec 16, 2020
- Messages
- 57
- Office Version
- 365
- Platform
- Windows
Hi,
I have the following code that allows me to select specific cells in an excel document and export them to a text file.
I want to modify the code so it will pre-fill the filename with the value found in cell B2.
I've found many examples of how to do this but just can't get any of the examples to work within my code.
Can anyone help out?
Thank you in advance
Sub ExportRangetoFile()
'Update 20210310
Dim wb As Workbook
Dim saveFile As String
Dim WorkRng As Range
On Error Resume Next
xTitleId = "COPY COLUMN B"
Set WorkRng = Application.Selection
Set WorkRng = Application.InputBox("Range", xTitleId, WorkRng.Address, Type:=8)
Application.ScreenUpdating = False
Application.DisplayAlerts = False
Set wb = Application.Workbooks.Add
WorkRng.Copy
wb.Worksheets(1).Paste
saveFile = Application.GetSaveAsFilename(fileFilter:="Text Files (*.txt), *.txt")
wb.SaveAs FileName:=saveFile, FileFormat:=xlText, CreateBackup:=False
wb.Close
Application.CutCopyMode = False
Application.DisplayAlerts = True
Application.ScreenUpdating = True
End Sub
I have the following code that allows me to select specific cells in an excel document and export them to a text file.
I want to modify the code so it will pre-fill the filename with the value found in cell B2.
I've found many examples of how to do this but just can't get any of the examples to work within my code.
Can anyone help out?
Thank you in advance
Sub ExportRangetoFile()
'Update 20210310
Dim wb As Workbook
Dim saveFile As String
Dim WorkRng As Range
On Error Resume Next
xTitleId = "COPY COLUMN B"
Set WorkRng = Application.Selection
Set WorkRng = Application.InputBox("Range", xTitleId, WorkRng.Address, Type:=8)
Application.ScreenUpdating = False
Application.DisplayAlerts = False
Set wb = Application.Workbooks.Add
WorkRng.Copy
wb.Worksheets(1).Paste
saveFile = Application.GetSaveAsFilename(fileFilter:="Text Files (*.txt), *.txt")
wb.SaveAs FileName:=saveFile, FileFormat:=xlText, CreateBackup:=False
wb.Close
Application.CutCopyMode = False
Application.DisplayAlerts = True
Application.ScreenUpdating = True
End Sub