Reputation: 77
i am having a major problem that i cannot figure out it is telling me i have a duplicate declaration....but i do not! I even changed the variable to something else and it still says it. Unfortunately my code is crazy long so i am only pasting the part that gives me the error. On the second line (dim c as integer) is where i get the error even if i change C to D, i still get the error, not sure how that is even possible. I have done a search, and the search shows that DIM C is the only one in my whole project!!!!!
Any thoughts, please i am crazy desperate....300 hours of coding for it to fail on a last tiny simple command.
I really really appreciate it!
Dim Msg As String
Dim C As Integer
Dim PrinterName As String
C = 1
On Error GoTo MakePDFError:
ResumePrinting:
If C < 10 Then
PrinterName = "Verdun_Office on Ne0" & C & ":"
Else
PrinterName = "Verdun_Office on Ne" & C & ":"
End If
Application.ActivePrinter = PrinterName
ActiveWindow.SelectedSheets.PrintOut Copies:=qty, ActivePrinter:= _
"Verdun_Office on Ne01:", collate:=True
Worksheets("invoice excel").Activate
Application.ActivePrinter = PrinterName
ActiveWindow.SelectedSheets.PrintOut Copies:=1, ActivePrinter:= _
"Verdun_Office on Ne01:", collate:=True
Exit Sub
MakePDFError:
C = C + 1
Resume ResumePrinting:
Upvotes: 0
Views: 3626
Reputation: 1
In my case it was because the block of Dim statements was too low down in the procedure. I moved them to the top and all was fine. I had NOT invoked the variable before the Dim statement. It just didn't like not getting the attention it wanted near the top of the subroutine! They are touchy these Dim statements.
Upvotes: 0
Reputation: 51
This happend to me today, my problem was I Dim de variable after calling it (not Dim still)
Example
Sub Dim_Duplicate()
VarD=23
'a lot of code here, so you not remember use the VarD before
Dim VarD as Integer
End Sub
Upvotes: 3
Reputation: 23285
It's likely due to your variable's name C
. As noted in the comments, best practice for variables (in VB, and programming in general) is to use a name that makes some sense to the user. C
tells us nothing. It looks like you're using that to store a row value, so why not use xRow
or iRow
(note: Don't use Row
since that's a special word within VB)?
Double check that C
isn't declared Globally, and change it (and all instances, see @Nathan_Sav's suggestion in the comments) to something else, such as iRow
.
Upvotes: 0