palaeontology
Active Member
- Joined
- May 12, 2017
- Messages
- 444
- Office Version
- 2016
- Platform
- Windows
I'm receiving an error message ... (Compile error: Duplicate declaration in current scope) ... when I run some code that has 13 components, but I believe it's the following two components that are the issue ...
one of the components copies a template sheet multiple times and renames them with names from a list ...
another component saves all sheets that have a 5-digit name as PDFs in a certain location in G:drive ...
it is the 'Dim ws As Worksheet' in the second of those two components that becomes highlighted with the error message, so I clearly can't have that appear twice, but how do I get around this ?
Any help would be appreciated.
Very kind regards,
Chris
one of the components copies a template sheet multiple times and renames them with names from a list ...
Code:
Dim ws As Worksheet, Ct As Long, c As RangeSet ws = Worksheets("Student Profile Template")
Application.ScreenUpdating = False
For Each c In Sheets("PrintTemplate").Range("AH49:AH100")
If c.Value <> "" Then
ws.Copy after:=Sheets(Sheets.Count)
ActiveSheet.Name = c.Value
Ct = Ct + 1
End If
Next c
Application.ScreenUpdating = True]
another component saves all sheets that have a 5-digit name as PDFs in a certain location in G:drive ...
Code:
Dim ws As Worksheet, wPath As String, r1 As String, r2 As String, r3 As String
wPath = "G:\Maths Dept\STUDENT RESULTS\2019\PDF Profile Copies\"
For Each ws In ThisWorkbook.Worksheets
If ws.Name Like "#####" Then
r1 = ws.Range("S5") & "\"
r2 = r1 & ws.Range("E2") & "\"
r3 = r2 & ws.Range("S3") & "\"
If Dir(wPath & r1, vbDirectory) = "" Then MkDir wPath & r1
If Dir(wPath & r2, vbDirectory) = "" Then MkDir wPath & r2
If Dir(wPath & r3, vbDirectory) = "" Then MkDir wPath & r3
ws.PageSetup.Orientation = xlLandscape
ws.Range("A1:ai29").ExportAsFixedFormat xlTypePDF, wPath & r3 & ws.Name & ".pdf"
End If
Next ws
it is the 'Dim ws As Worksheet' in the second of those two components that becomes highlighted with the error message, so I clearly can't have that appear twice, but how do I get around this ?
Any help would be appreciated.
Very kind regards,
Chris