The Ruff Report
New Member
- Joined
- Jun 17, 2023
- Messages
- 19
- Office Version
- 365
- Platform
- Windows
In the below I'm saving a file with a name based on the values in cells A1 and B1. Cell B1 though contains prohibited characters. In my case, they are "[", "]" and of course "/"
I would like to remove the prohibited characters from the file name but not alter the text in cell B1. Any help is appreciated.
------------------------------------------------------------------------------------------------------------------------------------------------
Dim X As Integer
Dim astrLinks As Variant
Dim Path As String
Dim filename As String
For X = 2 To 200
If Sheets("Suppliers").Range("A" & X).Value <> "" Then
Sheets("Suppliers").Range("A" & X).Copy
Sheets("DA Summary").Range("B1").PasteSpecial (xlPasteValues)
Application.CutCopyMode = False
Sheets("Suppliers").Range("A" & X).Copy
Sheets("Price Point Data").Range("E1").PasteSpecial (xlPasteValues)
Application.CutCopyMode = False
Sheets(Array("Invoice", "DA Summary", "Price Point Data")).Copy
Sheets("DA Summary").Select
Range("A1").Select
astrLinks = ActiveWorkbook.LinkSources(Type:=xlLinkTypeExcelLinks)
ActiveWorkbook.BreakLink _
Name:=astrLinks(1), _
Type:=xlLinkTypeExcelLinks
Path = "C:\Test Reports\"
filename = Range("A1") & " " & Range("B1")
ActiveWorkbook.SaveAs filename:=Path & filename & ".xlsx", FileFormat:=xlOpenXMLWorkbook, CreateBackup:=False
Application.CommandBars("Workbook Links").Visible = False
Sheets("Invoice").Select
Range("A1").Select
ActiveWorkbook.Save
ActiveWorkbook.Close
Windows("DA Chopper New.xlsm").Activate
End If
Next X
End Sub
I would like to remove the prohibited characters from the file name but not alter the text in cell B1. Any help is appreciated.
------------------------------------------------------------------------------------------------------------------------------------------------
Dim X As Integer
Dim astrLinks As Variant
Dim Path As String
Dim filename As String
For X = 2 To 200
If Sheets("Suppliers").Range("A" & X).Value <> "" Then
Sheets("Suppliers").Range("A" & X).Copy
Sheets("DA Summary").Range("B1").PasteSpecial (xlPasteValues)
Application.CutCopyMode = False
Sheets("Suppliers").Range("A" & X).Copy
Sheets("Price Point Data").Range("E1").PasteSpecial (xlPasteValues)
Application.CutCopyMode = False
Sheets(Array("Invoice", "DA Summary", "Price Point Data")).Copy
Sheets("DA Summary").Select
Range("A1").Select
astrLinks = ActiveWorkbook.LinkSources(Type:=xlLinkTypeExcelLinks)
ActiveWorkbook.BreakLink _
Name:=astrLinks(1), _
Type:=xlLinkTypeExcelLinks
Path = "C:\Test Reports\"
filename = Range("A1") & " " & Range("B1")
ActiveWorkbook.SaveAs filename:=Path & filename & ".xlsx", FileFormat:=xlOpenXMLWorkbook, CreateBackup:=False
Application.CommandBars("Workbook Links").Visible = False
Sheets("Invoice").Select
Range("A1").Select
ActiveWorkbook.Save
ActiveWorkbook.Close
Windows("DA Chopper New.xlsm").Activate
End If
Next X
End Sub