Inconsistent code

  • Thread starter Thread starter Stuart
  • Start date Start date
S

Stuart

For fCtr = LBound(PrintFiles) To UBound(PrintFiles)
Set PrintFiles(fCtr) = Workbooks.Open _
(FileName:=PrintFileNames(fCtr))
Range("A1").Select
'If it's the first workbook in the loop, and if the user wants to
'hide the same Column(s):
If fCtr = 1 Then
If Global_HideSameCols = True Then
'On Error Resume Next
* Set Global_ExclColRng = Application.InputBox("Use the left mouse " & _
"button with the Control key," & vbNewLine & "to select at least"
_
& " one cell in each column " & vbNewLine & "(or the entire" _
& ".column), to indicate those" & vbNewLine & "Columns to be" _
& " hidden. Click OK. when done", Type:=8)
'On Error GoTo 0
End If
End If
'But user might still want to hide a Column(s) in individual workbooks,
so:
If HideCols = True Then
If Global_HideSameCols = False Then
'On Error Resume Next
* Set Wkbk_ExclColRng = Application.InputBox("This is a test",
Type:=8)

If I direct the code through the first Set statement and select a range
to hide, then the code executes ok. If I direct it through the second Set
statement, I get an 'Object required' message.

Why is the code not working, and why is it inconsistent, please?

Regards.
 
You get an error if the user hits cancel since the inputbox returns false
instead of a range you can't

set Global_ExclColRng = False

that is why the error handlers are there (you commented them out). They
catch the error and ignore it.

You then have to test the object to see if it was set

if Global_ExclColRng is nothing then
msgbox "You clicked cancel"
End if
 
Back
Top