Can't activate an existing workbook

O

Oldjay

I have a workbook open but not active named 123Q and a
Range("Input!ab2") = 123

Private Sub CommandButton2_Click() 'Generates PDF Quote Form

Dim CurrentPrinter As Variant
Dim quotenumber As String
Dim quotenumber1 As String

quotenumber = Range("Input!ab2")
quotenumber1 = quotenumber + "Q" + ".xls"

'Windows("quotenumber1").Activate

Why do i get an error message "subscript out of range"

oldjay
 
J

JLGWhiz

Try changing from:

quotenumber = Range("Input!ab2")

To:

quotenumber = Worksheets("Input").Range("ab2")
 
P

perjessen69

I have a workbook open but not active named 123Q and a
Range("Input!ab2") = 123

Private Sub CommandButton2_Click() 'Generates PDF Quote Form

Dim CurrentPrinter As Variant
Dim quotenumber As String
Dim quotenumber1 As String

quotenumber = Range("Input!ab2")
quotenumber1 = quotenumber + "Q" + ".xls"

'Windows("quotenumber1").Activate

Why do i get an error message "subscript out of range"

oldjay

Hi

Try this:

quotenumber=Workbook("123Q").Worksheets("Input").Range("AB2").Value

Regards,

Per
 
O

Oldjay

Private Sub CommandButton2_Click() 'Generates PDF Quote Form

Dim CurrentPrinter As Variant
Dim quotenumber As String
Dim quotenumber1 As String

quotenumber = Worksheets("Input").Range("ab2")
quotenumber1 = quotenumber + "Q" + ".xls"

Windows("quotenumber1").Activate

Tried it but have the same result
 
T

Tim Zych

Take the quotes off the last line:

Windows(quotenumber1).Activate

With that change it works for me in a regular module.

But I agree with the other posts that suggest a different way to reference
the range, although I don't think that's why you are seeing the error.
 
O

Oldjay

Thanks That did the trick

Tim Zych said:
Take the quotes off the last line:

Windows(quotenumber1).Activate

With that change it works for me in a regular module.

But I agree with the other posts that suggest a different way to reference
the range, although I don't think that's why you are seeing the error.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top