Results 1 to 8 of 8

Thread: Excel 97 VBA Print Preview Options

  1. #1

    Thread Starter
    Lively Member TheFIDDLER's Avatar
    Join Date
    May 2002
    Location
    here and there and far away
    Posts
    126

    Excel 97 VBA Print Preview Options

    Anyone know a method to disable the Print Preview options using VBA for Excel 97?

    I mean disabling the Margin, Setup and Page Break buttons that are found at the top of the print preview screen.

    Thanks
    -----
    #VBA, VB 6 Professional Edition, Office XP Developper. Excel 97, Excel 2000, Excel XP

    I miss my VIC 20.
    Never should have upgraded to my commodore 64. ...

  2. #2
    Ex-Super Mod RobDog888's Avatar
    Join Date
    Apr 2001
    Location
    LA, Calif. Raiders #1 AKA:Gangsta Yoda™
    Posts
    60,709
    This will disable the menu item for print preview on Excel 2003.
    it should be the same on Excel 97.
    VB Code:
    1. Private Sub Workbook_Open()
    2.    
    3.     Dim oCtl As Office.CommandBarControl
    4.     Dim oCtl2 As Office.CommandBarPopup
    5.    
    6.     Set oCtl2 = Application.CommandBars("Worksheet Menu Bar").Controls("&File")
    7.     Set oCtl = oCtl2.CommandBar.FindControl(msoControlButton, Application.CommandBars("Standard").Controls("Print Pre&view").ID)
    8.     If Not oCtl Is Nothing Then
    9.         oCtl.Enabled = False
    10.     End If
    11.     Set oCtl = Nothing
    12.  
    13. End Sub
    HTH
    VB/Office Guru™ (AKA: Gangsta Yoda®)
    I dont answer coding questions via PM. Please post a thread in the appropriate forum.

    Microsoft MVP 2006-2011
    Office Development FAQ (C#, VB.NET, VB 6, VBA)
    Senior Jedi Software Engineer MCP (VB 6 & .NET), BSEE, CET
    If a post has helped you then Please Rate it!
    Reps & Rating PostsVS.NET on Vista Multiple .NET Framework Versions Office Primary Interop AssembliesVB/Office Guru™ Word SpellChecker™.NETVB/Office Guru™ Word SpellChecker™ VB6VB.NET Attributes Ex.Outlook Global Address ListAPI Viewer utility.NET API Viewer Utility
    System: Intel i7 6850K, Geforce GTX1060, Samsung M.2 1 TB & SATA 500 GB, 32 GBs DDR4 3300 Quad Channel RAM, 2 Viewsonic 24" LCDs, Windows 10, Office 2016, VS 2019, VB6 SP6

  3. #3

    Thread Starter
    Lively Member TheFIDDLER's Avatar
    Join Date
    May 2002
    Location
    here and there and far away
    Posts
    126
    Thanks, but not my question.

    I am not looking to remove the print preview icon from the menu bar. I am trying to disable or remove the options available within print preview itself.

    I can do this with Excel 02 and XP, but am looking for a method that works with the worksheet.printpreview command in Excel 97 via VBA.
    -----
    #VBA, VB 6 Professional Edition, Office XP Developper. Excel 97, Excel 2000, Excel XP

    I miss my VIC 20.
    Never should have upgraded to my commodore 64. ...

  4. #4
    Ex-Super Mod RobDog888's Avatar
    Join Date
    Apr 2001
    Location
    LA, Calif. Raiders #1 AKA:Gangsta Yoda™
    Posts
    60,709
    Sorry for the mixup, buti no longer have any systems with Office
    97 on them. Can you post your code for XP? Maybe I can think of
    a way. Is the worksheet.printpreview method not available in 97?
    VB/Office Guru™ (AKA: Gangsta Yoda®)
    I dont answer coding questions via PM. Please post a thread in the appropriate forum.

    Microsoft MVP 2006-2011
    Office Development FAQ (C#, VB.NET, VB 6, VBA)
    Senior Jedi Software Engineer MCP (VB 6 & .NET), BSEE, CET
    If a post has helped you then Please Rate it!
    Reps & Rating PostsVS.NET on Vista Multiple .NET Framework Versions Office Primary Interop AssembliesVB/Office Guru™ Word SpellChecker™.NETVB/Office Guru™ Word SpellChecker™ VB6VB.NET Attributes Ex.Outlook Global Address ListAPI Viewer utility.NET API Viewer Utility
    System: Intel i7 6850K, Geforce GTX1060, Samsung M.2 1 TB & SATA 500 GB, 32 GBs DDR4 3300 Quad Channel RAM, 2 Viewsonic 24" LCDs, Windows 10, Office 2016, VS 2019, VB6 SP6

  5. #5

    Thread Starter
    Lively Member TheFIDDLER's Avatar
    Join Date
    May 2002
    Location
    here and there and far away
    Posts
    126
    Starting with 02 (I think), Excel can do what I am looking for with the worksheet.printpreview event, and using the parameter of EnableChanges = false. Setting the EnableChanges parameter to false disabled the Margins and Setup button, hence preventing the user from modifying my page setup.

    It just doesn't work in 97 and I was wondering if someone came up with another method to accomplish this.
    -----
    #VBA, VB 6 Professional Edition, Office XP Developper. Excel 97, Excel 2000, Excel XP

    I miss my VIC 20.
    Never should have upgraded to my commodore 64. ...

  6. #6
    Ex-Super Mod RobDog888's Avatar
    Join Date
    Apr 2001
    Location
    LA, Calif. Raiders #1 AKA:Gangsta Yoda™
    Posts
    60,709
    Maybe as a temporary solution for 97 you could just disable the
    print preview and only let them actually print the spreadsheet?

    Or if the version is 97 you could hide the standard print preview
    menu item and toolbar button and then create your own it their
    place. This may give you more flexability in controlling the buttons
    on the print preview form. you can "FindWindow and
    FindWindowEx APIs to get the handel to the buttons and change
    the style to disabled or hide them using SetWindowLong.

    The only issue to get around would be the modal state of the
    print preview window. Your findwindow code will not execute until
    the print preview window is closed. To get around this you could
    add the FindWindow code in a separate .exe and kick it off right
    before you show the print preview window. Then it will be able to
    interact with the print preview window without the limitation of
    the Modality issue. Then close itself down after the changes are
    made to the print preview window. Kind of like using two
    programs to simulate multi-threading.

    Hope I explained myself well.
    VB/Office Guru™ (AKA: Gangsta Yoda®)
    I dont answer coding questions via PM. Please post a thread in the appropriate forum.

    Microsoft MVP 2006-2011
    Office Development FAQ (C#, VB.NET, VB 6, VBA)
    Senior Jedi Software Engineer MCP (VB 6 & .NET), BSEE, CET
    If a post has helped you then Please Rate it!
    Reps & Rating PostsVS.NET on Vista Multiple .NET Framework Versions Office Primary Interop AssembliesVB/Office Guru™ Word SpellChecker™.NETVB/Office Guru™ Word SpellChecker™ VB6VB.NET Attributes Ex.Outlook Global Address ListAPI Viewer utility.NET API Viewer Utility
    System: Intel i7 6850K, Geforce GTX1060, Samsung M.2 1 TB & SATA 500 GB, 32 GBs DDR4 3300 Quad Channel RAM, 2 Viewsonic 24" LCDs, Windows 10, Office 2016, VS 2019, VB6 SP6

  7. #7

    Thread Starter
    Lively Member TheFIDDLER's Avatar
    Join Date
    May 2002
    Location
    here and there and far away
    Posts
    126
    Sounds a bit more work than I was intending for.

    But where I do need this for my software, I will file this under my to do list.

    As best as I can imagine, Microsoft added the extra functionality as this did not exist for 97. Really bad stuff when a user changes my margins and my page setup and then calls me to say my application does not print correctly. I'm just trying to be proactive and remove what they shouldn't be playing with.


    Thanks
    -----
    #VBA, VB 6 Professional Edition, Office XP Developper. Excel 97, Excel 2000, Excel XP

    I miss my VIC 20.
    Never should have upgraded to my commodore 64. ...

  8. #8
    Ex-Super Mod RobDog888's Avatar
    Join Date
    Apr 2001
    Location
    LA, Calif. Raiders #1 AKA:Gangsta Yoda™
    Posts
    60,709
    No problem. I have the same issue with our client
    management / employee time program. Our employees print out
    service calls or their time card and is shells out to wordpad on our
    terminal server and it is formatted to print on 1/2" margins, but
    wordpad's default is 1 1/4". Changing the forms are not an
    option so I used the method above until I found the registry key
    for the print margins in hex. so now I just make sure that the
    margins in the registry are the appropriate values and if not I
    update them and after I set it back and they have no idea.
    VB/Office Guru™ (AKA: Gangsta Yoda®)
    I dont answer coding questions via PM. Please post a thread in the appropriate forum.

    Microsoft MVP 2006-2011
    Office Development FAQ (C#, VB.NET, VB 6, VBA)
    Senior Jedi Software Engineer MCP (VB 6 & .NET), BSEE, CET
    If a post has helped you then Please Rate it!
    Reps & Rating PostsVS.NET on Vista Multiple .NET Framework Versions Office Primary Interop AssembliesVB/Office Guru™ Word SpellChecker™.NETVB/Office Guru™ Word SpellChecker™ VB6VB.NET Attributes Ex.Outlook Global Address ListAPI Viewer utility.NET API Viewer Utility
    System: Intel i7 6850K, Geforce GTX1060, Samsung M.2 1 TB & SATA 500 GB, 32 GBs DDR4 3300 Quad Channel RAM, 2 Viewsonic 24" LCDs, Windows 10, Office 2016, VS 2019, VB6 SP6

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width