|
|

June 10th, 2005
|
|
|
|
variant array subscript error
What have I missed? THANKS for looking!
strTempAry is a 1000 cell list in column H in a worksheet within the workbook.
VB: AutoLinked keywords will cause extra spaces before keywords. Extra spacing is NOT transferred when copy/pasting, but IS if the keyword uses "quotes".
Private Sub Workbook_BeforePrint(Cancel As Boolean)
Dim strTempAry As Variant
Dim x As Integer
strTempAry = Worksheets("PrintList").Range("H1:H1000")
For Each wk In Worksheets
wk.Calculate
wk.Activate
x = wk.Range("I3:I3")
Select Case wk.Name
Case "Compliance Program"
Case "Printable Program"
Case "PrintList"
Case Else
If strTempAry(x) = 1 Then PrintOut
End Select
Next
End Sub
|

June 10th, 2005
|
Intelligent Converters
FREE DOWNLOADS
File/Password Recovery
|
Have VBA, will travel
|
|
I'm a Spammer:
MS Office Version: 97 forwards
Op System: Win ME to Win XP
Assumed Experience: ...still learning...
Join Date: 24th December 2004
English is 1st Language: Yes
Location: Nanaimo, Vancouver Island, British Columbia, Canada
|
|
|
Re: variant array subscript error
Hi,
Note on code tags opening is [ code ] and close is [ /code ] (no spaces)... Good try tho! As for your question, I'm not sure but you're trying to build an array? Try this code:
VB: AutoLinked keywords will cause extra spaces before keywords. Extra spacing is NOT transferred when copy/pasting, but IS if the keyword uses "quotes".
Option Base 1
Private Sub Workbook_BeforePrint(Cancel As Boolean)
Dim strTempAry(1000)
Dim x, r, c, i As Integer
r = 1
c = 8
For i = 1 To 1000
strTempAry(i) = Worksheets("PrintList"). Cells(r, c).Value
r = r + 1
Next
For Each wk In Worksheets
wk.Calculate
wk.Activate
x = wk.Range("I3:I3")
Select Case wk.Name
Case "Compliance Program"
Case "Printable Program"
Case "PrintList"
End Select
If x = "" Then Goto phred
If strTempAry(x) = 1 Then PrintOut
phred:
Next
End Sub
Cheers,
dr
|

June 11th, 2005
|
|
|
|
Re: variant array subscript error
Hi rbrhodes!
You are correct, I am loading an array with a Print/NoPrint code (1 or 0). The program finds each worksheet in the workbook, calculates it, makes it active (to adjust for merged cell row height), examines the unique worksheet number (which ascends numerically from 1 starting with the first worksheet, all 'never print' worksheets contain "" in this worksheet cell), looks that number up in the array, and if it is a '1' it prints the active worksheet.
Thanks! Solved some problems but still have just one ...
Problems solved:
1.) Array loads up fine now. THANKS!
2.) Using your code the Case statements were not needed.
3.) Evidently the wk.Activate is a 'one-time' command so that by the time PrintOut is executed the program no longer knows which sheet is active so I made it 'wk.PrintOut' and that works fine.
Problem that remains:
Last record processing - The last worksheet is specified to Not Print but it prints anyway - I must be missing some kind of special last record code, huh?
Can you help identify it?
|

June 11th, 2005
|
 |
OzMVP
|
|
I'm a Spammer: NO
MS Office Version: 2000 English
Op System: Windows Vista
Assumed Experience: Expert (I wont be needing help)
Join Date: 14th July 2004
English is 1st Language: Yes
|
|
|
Re: variant array subscript error
Jeff
The array you created was a 1000 by 1 array.
So when you tried this you were missing the second dimension.
VB: AutoLinked keywords will cause extra spaces before keywords. Extra spacing is NOT transferred when copy/pasting, but IS if the keyword uses "quotes".
strTempAry(x)
|

June 11th, 2005
|
 |
OzMVP
|
|
I'm a Spammer:
MS Office Version: 2003
Op System: Windows XP
Assumed Experience: Still learning!
Join Date: 25th January 2003
English is 1st Language:
Location: UK
|
|
|
Re: variant array subscript error
Hi Jeff,
If you are one record out then make sure that you copied the first line of dr's code - Option Base 1. The default lower bound for arrays is 0, the use of the Option Base 1 statement indicates that they should start at 1. (I haven't checked the code - just speculating  )
dr,
Do you realise that in the line :
Dim x, r, c, i As Integer
only i is declared as an Integer (the others are Variant types). Each variable must be specifically assigned the desired type.
|

June 11th, 2005
|
|
|
|
Re: variant array subscript error
Hi Norie, Thanks! So....
The following would have worked for the 'As Variant' option of loading the array in the original code?
VB: AutoLinked keywords will cause extra spaces before keywords. Extra spacing is NOT transferred when copy/pasting, but IS if the keyword uses "quotes".
Dim c As Integer
c = 8
strTempAry(x,c) = 1 Then ...
|

June 11th, 2005
|
|
|
|
Re: variant array subscript error
Hi Richie (UK)!
Thanks for the info. No I did not know that.
regarding the Option Base 1, yes, it is in the code.
Regarding the PrintOut problem - I think that XL 'batches' print output while the procedure is running, and releases all of it when the procedure is complete.
The Print icon was selected to activate the workbook macro, but nothing was manually selected to print. It appears that XL feels that it needs to print something because the icon was selected so it prints the last worksheet that it touched.
I tried setting Cancel to TRUE after the Next statement but only succeeded in canceling all the PrintOut output. (which leads me to believe that output is batched while the procedure is running)
So I guess I am looking for a way to supress XL automatic printing of the last worksheet touched.
Does this help clarify?
Thanks again,
Jeff
|

June 11th, 2005
|
Intelligent Converters
FREE DOWNLOADS
File/Password Recovery
|
Have VBA, will travel
|
|
I'm a Spammer:
MS Office Version: 97 forwards
Op System: Win ME to Win XP
Assumed Experience: ...still learning...
Join Date: 24th December 2004
English is 1st Language: Yes
Location: Nanaimo, Vancouver Island, British Columbia, Canada
|
|
|
Re: variant array subscript error
Hi,
Quote:
dr,
Do you realise that in the line :
Dim x, r, c, i As Integer
only i is declared as an Integer (the others are Variant types). Each variable must be specifically assigned the desired type.
|
Richie, thanks for the reminder! I saw a dim statement like this and presumed it was a 'collective' Dim. I did try it and realized it was not, but I guess I forgot (or got lazy?)!
Jeff,
Regarding the 'LAST' sheet printing when it should not: do you mean the last run of the If..Then..Print is failing the "is 1" test but printing anyway? Is that right?
Cheers,
dr
|

June 11th, 2005
|
|
|
|
Re: variant array subscript error
Hi dr,
Yes, correct.
The last worksheet is set to '0' so that it should not print but it does anyway.
This issue has shown up before (printing the last worksheet touched even when not selected to print) but was not an issue until now.
jeff
|

June 11th, 2005
|
Intelligent Converters
FREE DOWNLOADS
File/Password Recovery
|
Have VBA, will travel
|
|
I'm a Spammer:
MS Office Version: 97 forwards
Op System: Win ME to Win XP
Assumed Experience: ...still learning...
Join Date: 24th December 2004
English is 1st Language: Yes
Location: Nanaimo, Vancouver Island, British Columbia, Canada
|
|
|
Re: variant array subscript error
Hi Jeff,
Thats very strange because if x = 0 then there should be an error!
This is because I used Option Base 1. So strTempAry(x), with x = zero is an error.
To correct that substitute this line in:
If x = "" Or x = 0 Then GoTo phred
This may correct the print problem as well...let me know as it it worked for me!
Cheers,
dr
|
« PREVIOUS How to cut one sheet's values and paste it in other sheet? || Format NEXT »
|
Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
|
|
|
| Thread Tools |
Search this Thread |
|
|
|
Posting Rules
|
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts
HTML code is Off
|
|
|
All times are GMT +9. The time now is 10:21.
|