hide columns before printing

  • Thread starter Jean-Paul De Winter
  • Start date
J

Jean-Paul De Winter

Hi,

Before actually printing my sheet I want to hide column A and B.
Can I do this automatically without having to hide them manually?

Thanks
 
J

Jarek Kujawa

press ALT+F11 to get to VBA
then in Project-VBA Project window double click on ThisWorkbook
put this code into the window to the right:

Private Sub Workbook_BeforePrint(Cancel As Boolean)
Range("A:B").Columns.Entirecolumn.Hidden = True
End Sub


HIH
pls click YES if it helped
 
J

Jean-Paul

Hi,

Thanks for the code, it works, but, after printing and returning to the
worksheet, both columns remain hidden..
How can I automatically make them visible again??

Thanks

Jarek said:
press ALT+F11 to get to VBA
then in Project-VBA Project window double click on ThisWorkbook
put this code into the window to the right:

Private Sub Workbook_BeforePrint(Cancel As Boolean)
Range("A:B").Columns.Entirecolumn.Hidden = True
End Sub


HIH
pls click YES if it helped
 
J

Jarek Kujawa

Jean_Paul's and Dave's solution is better

but if you prefer to stick with VBA then you might use this one (which
is far from perfect):

Sub Makro1()

For i = 1 To ActiveWindow.SelectedSheets.Count
names_string= names_string & Sheets(i).Name
Next i

If names_string Like "*Sheet1*" Then Arkusz1.Columns("A:B").Hidden =
True

ActiveWindow.SelectedSheets.PrintOut Copies:=1, Collate:=True

If names_string Like "*Sheet1*" Then Arkusz1.Columns("A:B").Hidden =
False

End Sub

adjust your sheet names and columns
 

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