Macro not setting password and also how can I get user to print then carry on with macro.

ghrek

Active Member
Joined
Jul 29, 2005
Messages
273
Hi

I have started a macro but need help please.

I have set a password on the sheet to protect it and have a macro where I want to unprotect it and then set up area to print.
The user then selects the printer in which to print to and then I need it to re protect.

This is what I have so far. Any Ideas?

Rich (BB code):
 ActiveSheet.Unprotect  ( need it to automatically input password)
    ActiveWindow.SmallScroll Down:=40
    Range("B54:H107").Select

Then need it to print area selected above and user to select printer in which to print to and then carry on
by reprotecting sheet.

Range("N36").Select
    ActiveWindow.SmallScroll Down:=-68
    Cells.Select
    Selection.Locked = False
    Selection.FormulaHidden = False
    Range("8:1048576,E5:XFD7,A5:B7,1:4").Select
    Range("A1").Activate
    ActiveWindow.SmallScroll Down:=0
    Range("23:1048576,I11:XFD22,A11:G22,8:10,E5:XFD7,A5:B7,1:4").Select
    Range("A1").Activate
    ActiveWindow.SmallScroll Down:=28
    Range( _
        "39:1048576,E34:XFD38,A34:C38,23:33,I11:XFD22,A11:G22,8:10,E5:XFD7,A5:B7,1:4"). _
        Select
    Range("A1").Activate
    ActiveWindow.SmallScroll Down:=8
    Range( _
        "48:1048576,I46:XFD47,A46:A47,39:45,E34:XFD38,A34:C38,23:33,I11:XFD22,A11:G22,8:10,E5:XFD7,A5:B7,1:4" _
        ).Select
    Range("A1").Activate
    ActiveWindow.SmallScroll Down:=8
    Range( _
        "57:1048576,I56:XFD56,A56:F56,48:55,I46:XFD47,A46:A47,39:45,E34:XFD38,A34:C38,23:33,I11:XFD22,A11:G22,8:10,E5:XFD7,A5:B7,1:4" _
        ).Select
    Range("A1").Activate
    ActiveWindow.SmallScroll Down:=8
    Range( _
        "72:1048576,D60:XFD71,A60:B71,57:59,I56:XFD56,A56:F56,48:55,I46:XFD47,A46:A47,39:45,E34:XFD38,A34:C38,23:33,I11:XFD22,A11:G22,8:10,E5:XFD7,A5:B7,1:4" _
        ).Select
    Range("A1").Activate
    ActiveWindow.SmallScroll Down:=12
    Range( _
        "89:1048576,D81:XFD88,A81:B88,78:80,I77:XFD77,A77:F77,72:76,D60:XFD71,A60:B71,57:59,I56:XFD56,A56:F56,48:55,I46:XFD47,A46:A47,39:45,E34:XFD38,A34:C38,23:33,I11:XFD22,A11:G22,8:10,E5:XFD7,A5:B7,1:4" _
        ).Select
    Range("A1").Activate
    ActiveWindow.SmallScroll Down:=12
    Range( _
        "102:1048576,D94:XFD101,A94:B101,I93:XFD93,A93:F93,89:92,D81:XFD88,A81:B88,78:80,I77:XFD77,A77:F77,72:76,D60:XFD71,A60:B71,57:59,I56:XFD56,A56:F56,48:55,I46:XFD47,A46:A47,39:45,E34:XFD38,A34:C38,23:33,I11:XFD22,A11:G22,8:10,E5:XFD7,A5:B7,1:4" _
        ).Select
    Range("A1").Activate
    ActiveWindow.SmallScroll Down:=-84
    Selection.Locked = True
    Selection.FormulaHidden = False
    ActiveSheet.Protect DrawingObjects:=False, Contents:=True, Scenarios:= _
        False
Need it to reprotect sheet and input password automatically.
    ActiveWorkbook.Save
End Sub


Any Ideas?

Thanks
 

Excel Facts

Select a hidden cell
Somehide hide payroll data in column G? Press F5. Type G1. Enter. Look in formula bar while you arrow down through G.

hajiali

Active Member
Joined
Sep 8, 2018
Messages
392
Office Version
  1. 2016
Platform
  1. Windows
try
to unprotect
VBA Code:
ActiveSheet.Unprotect Password:="SetPassword"
set the password inside " "

" your print code here"

to protect
VBA Code:
ActiveSheet.Protect Password:="SetPassword"
 

GWteB

Well-known Member
Joined
Sep 10, 2010
Messages
1,295
Office Version
  1. 2013
Platform
  1. Windows
How about ...

VBA Code:
Sub ghrek()

    Const cPassword As String = "YourSecretPassword"    ' <<< change password to suit
    
    Dim oWs As Worksheet
    Set oWs = ThisWorkbook.Worksheets("Sheet1")         ' <<< change worksheet name to suit

    With oWs
        .Unprotect Password:=cPassword
        .PageSetup.PrintArea = "$B$54:$H$107"
        Application.Dialogs(xlDialogPrint).Show
        .Cells.Locked = True
        .Cells.FormulaHidden = False
        .Range("C5:D7,H11:H22,D34:D38,B46:H47,G56:H56,C60:C71,G77:H77,C81:C88,G93:H93,C94:C101").Locked = False
        .Protect Password:=cPassword, DrawingObjects:=False, Contents:=True, Scenarios:=False
        oWs.Parent.Save
    End With
End Sub
 
Solution

Watch MrExcel Video

Forum statistics

Threads
1,129,863
Messages
5,638,742
Members
417,049
Latest member
baka416

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Top