Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.misc
Olle Svensson
 
Posts: n/a
Default Macro for hiding and printing.

Hi.
I want to put in a macro that simply hides columns W-AC in all sheets and
then prints the entire workbook. Sounds rather easy but being a rookie at
macros, I can not do it myself.

Therefore, I hope someone might be able to throw something together for me,
please?


Kind regards,
Olle Svensson
  #2   Report Post  
Posted to microsoft.public.excel.misc
Dave Peterson
 
Posts: n/a
Default Macro for hiding and printing.

Like this?

Option Explicit
Sub testme()

Dim wks As Worksheet

For Each wks In ActiveWorkbook.Worksheets
wks.Range("w:ac").EntireColumn.Hidden = True
Next wks

ActiveWorkbook.PrintOut preview:=True 'save paper for testing

For Each wks In ActiveWorkbook.Worksheets
wks.Range("w:ac").EntireColumn.Hidden = False
Next wks

End Sub



Olle Svensson wrote:

Hi.
I want to put in a macro that simply hides columns W-AC in all sheets and
then prints the entire workbook. Sounds rather easy but being a rookie at
macros, I can not do it myself.

Therefore, I hope someone might be able to throw something together for me,
please?

Kind regards,
Olle Svensson


--

Dave Peterson
  #3   Report Post  
Posted to microsoft.public.excel.misc
Olle Svensson
 
Posts: n/a
Default Macro for hiding and printing.

Thanks, but unfortunately, that did not work at all. I've been trying to use
this:

Private Sub Workbook_BeforePrint(Cancel As Boolean)
If ActiveSheet.Name = "Sheet1" Then
Cancel = True
Application.EnableEvents = False
Application.ScreenUpdating = False
With ActiveSheet
.Range("W1,AC1").EntireColumn.Hidden = True
.PrintOut
.Range("W1,AC1").EntireColumn.Hidden = False
End With
Application.EnableEvents = True
Application.ScreenUpdating = True
End If
End Sub

Maybe I am doing it wrong, but I go to the Microsoft Visual Basic, paste it
under Microsoft Excel Objects -- ThisWorkbook, save and exit to Excel. Then
I press the print button but nothing happens. Well, the print comes out but
with the undesired columns still visible.

If it's not possible to tie it to the print button (or File -- Print) then
would it be possible to make a macro of it that I can assign to a button on
one of the sheets?



"Dave Peterson" wrote:

Like this?

Option Explicit
Sub testme()

Dim wks As Worksheet

For Each wks In ActiveWorkbook.Worksheets
wks.Range("w:ac").EntireColumn.Hidden = True
Next wks

ActiveWorkbook.PrintOut preview:=True 'save paper for testing

For Each wks In ActiveWorkbook.Worksheets
wks.Range("w:ac").EntireColumn.Hidden = False
Next wks

End Sub



Olle Svensson wrote:

Hi.
I want to put in a macro that simply hides columns W-AC in all sheets and
then prints the entire workbook. Sounds rather easy but being a rookie at
macros, I can not do it myself.

Therefore, I hope someone might be able to throw something together for me,
please?

Kind regards,
Olle Svensson


--

Dave Peterson

  #4   Report Post  
Posted to microsoft.public.excel.misc
Dave Peterson
 
Posts: n/a
Default Macro for hiding and printing.

What happened when you tried it? How did you try it? Since it worked ok for
me.

======

If you want a button on a single sheet, then toss the _beforeprint code and put
that suggestion into a general module.

Then show the Forms toolbar. Drag a button to the worksheet. Assign it the
macro in the General module.

Then test it out.

Your code only works on the activesheet (not all of them) and only if it's named
Sheet1.

And .range(w1,ac1).entirecolumn is just those two columns--not W:AC.



Olle Svensson wrote:

Thanks, but unfortunately, that did not work at all. I've been trying to use
this:

Private Sub Workbook_BeforePrint(Cancel As Boolean)
If ActiveSheet.Name = "Sheet1" Then
Cancel = True
Application.EnableEvents = False
Application.ScreenUpdating = False
With ActiveSheet
.Range("W1,AC1").EntireColumn.Hidden = True
.PrintOut
.Range("W1,AC1").EntireColumn.Hidden = False
End With
Application.EnableEvents = True
Application.ScreenUpdating = True
End If
End Sub

Maybe I am doing it wrong, but I go to the Microsoft Visual Basic, paste it
under Microsoft Excel Objects -- ThisWorkbook, save and exit to Excel. Then
I press the print button but nothing happens. Well, the print comes out but
with the undesired columns still visible.

If it's not possible to tie it to the print button (or File -- Print) then
would it be possible to make a macro of it that I can assign to a button on
one of the sheets?

"Dave Peterson" wrote:

Like this?

Option Explicit
Sub testme()

Dim wks As Worksheet

For Each wks In ActiveWorkbook.Worksheets
wks.Range("w:ac").EntireColumn.Hidden = True
Next wks

ActiveWorkbook.PrintOut preview:=True 'save paper for testing

For Each wks In ActiveWorkbook.Worksheets
wks.Range("w:ac").EntireColumn.Hidden = False
Next wks

End Sub



Olle Svensson wrote:

Hi.
I want to put in a macro that simply hides columns W-AC in all sheets and
then prints the entire workbook. Sounds rather easy but being a rookie at
macros, I can not do it myself.

Therefore, I hope someone might be able to throw something together for me,
please?

Kind regards,
Olle Svensson


--

Dave Peterson


--

Dave Peterson
  #5   Report Post  
Posted to microsoft.public.excel.misc
Olle Svensson
 
Posts: n/a
Default Macro for hiding and printing.



"Dave Peterson" wrote:

What happened when you tried it? How did you try it? Since it worked ok for
me.


Like I wrote in the above post:
Maybe I am doing it wrong, but I go to Microsoft Visual Basic, from Excel,
paste it
under Microsoft Excel Objects -- ThisWorkbook, save and exit to Excel. Then
I press the print button but nothing happens. Well, the print comes out but
with the undesired columns still visible.

I'm not sure if I need a command for it to be used with all sheets when I
print but if possible, that's what I want.



  #6   Report Post  
Posted to microsoft.public.excel.misc
Dave Peterson
 
Posts: n/a
Default Macro for hiding and printing.

Don't put it under ThisWorkbook.

Select your project and Insert|Module

Paste the code in that new window.

Then either run the code (tools|macro|macros) or assign it to a button from the
Forms toolbar.



Olle Svensson wrote:

"Dave Peterson" wrote:

What happened when you tried it? How did you try it? Since it worked ok for
me.


Like I wrote in the above post:
Maybe I am doing it wrong, but I go to Microsoft Visual Basic, from Excel,
paste it
under Microsoft Excel Objects -- ThisWorkbook, save and exit to Excel. Then
I press the print button but nothing happens. Well, the print comes out but
with the undesired columns still visible.

I'm not sure if I need a command for it to be used with all sheets when I
print but if possible, that's what I want.


--

Dave Peterson
Reply
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
Repeat form printing with new data by macro Alec H Excel Discussion (Misc queries) 1 February 22nd 06 03:26 PM
Printing spreadsheets macro GarToms Excel Discussion (Misc queries) 5 February 8th 06 03:11 PM
printing macro johnw Excel Discussion (Misc queries) 0 October 7th 05 02:31 PM
Printing Macro kwedde01 Excel Discussion (Misc queries) 1 June 10th 05 04:36 AM
Printing Macro kwedde01 Excel Worksheet Functions 0 June 9th 05 11:05 PM


All times are GMT +1. The time now is 10:26 AM.

Powered by vBulletin® Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
Copyright ©2004-2024 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"