Home |
Search |
Today's Posts |
#1
Posted to microsoft.public.excel.misc
|
|||
|
|||
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
Posted to microsoft.public.excel.misc
|
|||
|
|||
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
Posted to microsoft.public.excel.misc
|
|||
|
|||
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
Posted to microsoft.public.excel.misc
|
|||
|
|||
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
Posted to microsoft.public.excel.misc
|
|||
|
|||
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
Posted to microsoft.public.excel.misc
|
|||
|
|||
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 |
Display Modes | |
|
|
Similar Threads | ||||
Thread | Forum | |||
Repeat form printing with new data by macro | Excel Discussion (Misc queries) | |||
Printing spreadsheets macro | Excel Discussion (Misc queries) | |||
printing macro | Excel Discussion (Misc queries) | |||
Printing Macro | Excel Discussion (Misc queries) | |||
Printing Macro | Excel Worksheet Functions |