Microsoft Office Forums

Go Back   Microsoft Office Forums > >

Reply
 
Thread Tools Display Modes
  #1  
Old 05-06-2014, 11:24 AM
ksigcajun ksigcajun is offline Hiding Command Buttons before PDF Windows 7 64bit Hiding Command Buttons before PDF Office 2010 64bit
Advanced Beginner
Hiding Command Buttons before PDF
 
Join Date: May 2014
Posts: 76
ksigcajun is on a distinguished road
Default Hiding Command Buttons before PDF

Hey everyone! New to the board and looking for some help. I know this is pretty simple, but Im looking to hide a command button when a person clicks the button to PDF. I want a user to click this button, PDF their document and the button will not show on the PDF.

Here is my code and thanks for the helping a newbie!


Code:
Private Sub CommandButton111_Click() 
    Dim outl As Object 
    Dim Mail As Object 
    Dim Msg, Style, Title, Help, Ctxt, Response, MyString 
    Dim PDFname As String 
 
    Msg = "Your Document will be saved as PDF before mailing it as attachment, please agree?" 
    Style = vbOKCancel + vbQuestion + vbDefaultButton2 
    Title = "Document" 
    Ctxt = 1000 
    Response = MsgBox(Msg, Style, Title, Help, Ctxt) 
    If Response = vbOK Then 
        ActiveDocument.Save 
        PDFname = ActiveDocument.Path & "\" & "Document.pdf" 
        ActiveDocument.ExportAsFixedFormat OutputFileName:=PDFname, _
          ExportFormat:=wdExportFormatPDF, OpenAfterExport:=False, _
          OptimizeFor:=wdExportOptimizeForPrint, Range:=wdExportAllDocument, _
          Item:=wdExportDocumentContent, IncludeDocProps:=True, KeepIRM:=True, _
          CreateBookmarks:=wdExportCreateNoBookmarks, DocStructureTags:=True, _
          BitmapMissingFonts:=True, UseISO19005_1:=False 
        Set outl = CreateObject("Outlook.Application") 
        Set Mail = outl.CreateItem(0) 
        Mail.Subject = "Document" 
        Mail.HTMLBody = "Document<br> <br> <img src='image.gif'>" 
        Mail.To = "" 
        Mail.Attachments.Add PDFname 
        Mail.Display 
    Else 
        MsgBox "You have chosen not to save PDF and your file will not be sent" 
        Cancel = True 
    End If 
End Sub

Last edited by macropod; 05-06-2014 at 04:11 PM. Reason: Added code tags & formatting
Reply With Quote
  #2  
Old 05-06-2014, 04:23 PM
macropod's Avatar
macropod macropod is offline Hiding Command Buttons before PDF Windows 7 32bit Hiding Command Buttons before PDF Office 2010 32bit
Administrator
 
Join Date: Dec 2010
Location: Canberra, Australia
Posts: 21,962
macropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond repute
Default

If this is an ActiveX command button, you could pass the processing off to a second macro that handles the PDF creation & emailing. As part of that process, it could delete the command button, then restore it again (via Application.Undo) after the PDF has been created.

PS: When posting code, please use the code tags. They're on the 'Go Advanced' tab at the bottom of this screen.
PPS: You could reduce:
Code:
         ActiveDocument.ExportAsFixedFormat OutputFileName:=PDFname, _
          ExportFormat:=wdExportFormatPDF, OpenAfterExport:=False, _
          OptimizeFor:=wdExportOptimizeForPrint, Range:=wdExportAllDocument, _
          Item:=wdExportDocumentContent, IncludeDocProps:=True, KeepIRM:=True, _
          CreateBookmarks:=wdExportCreateNoBookmarks, DocStructureTags:=True, _
          BitmapMissingFonts:=True, UseISO19005_1:=False
to:
Code:
        ActiveDocument.SaveAs2 FileName:=PDFname, FileFormat:=wdFormatPDF
__________________
Cheers,
Paul Edstein
[Fmr MS MVP - Word]
Reply With Quote
  #3  
Old 05-07-2014, 05:15 AM
ksigcajun ksigcajun is offline Hiding Command Buttons before PDF Windows 7 64bit Hiding Command Buttons before PDF Office 2010 64bit
Advanced Beginner
Hiding Command Buttons before PDF
 
Join Date: May 2014
Posts: 76
ksigcajun is on a distinguished road
Default

Thanks MacroPod. I'll use the code tags from now on.

When you referenced using a second macro to create the PDF and email, plus the delete the command button and add it back, why can't I use the macro I currently have built to do it?

Can't I just add a delete command button function and have it add it back once the PDF has been created and put into an email?

What code would delete a command button and add it back?

Thanks!
Reply With Quote
  #4  
Old 05-07-2014, 05:31 AM
macropod's Avatar
macropod macropod is offline Hiding Command Buttons before PDF Windows 7 32bit Hiding Command Buttons before PDF Office 2010 32bit
Administrator
 
Join Date: Dec 2010
Location: Canberra, Australia
Posts: 21,962
macropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond repute
Default

Quote:
Originally Posted by ksigcajun View Post
When you referenced using a second macro to create the PDF and email, plus the delete the command button and add it back, why can't I use the macro I currently have built to do it?
That's just a precaution. I haven't tested it but I was concerned that deleting the button from the macro that runs it might kill the macro. If that doesn't occur, then it should be OK.
Quote:
What code would delete a command button and add it back?
You could use code like:
Code:
Me.CommandButton111.Select
Selection.Delete
'do your printout here
ActiveDocument.Undo
__________________
Cheers,
Paul Edstein
[Fmr MS MVP - Word]
Reply With Quote
Reply

Thread Tools
Display Modes


Similar Threads
Thread Thread Starter Forum Replies Last Post
Hiding Command Buttons before PDF Command buttons on slidemaster chcope PowerPoint 2 06-13-2013 04:30 PM
Check Boxes and Command Buttons Micky P Word VBA 0 10-27-2011 01:06 AM
Command Buttons lorenambrose Word 0 10-06-2011 11:55 AM
command buttons ronf Excel 0 04-28-2006 08:32 AM
command buttons ronf Excel 0 12-03-2005 06:26 AM

Other Forums: Access Forums

All times are GMT -7. The time now is 04:33 AM.


Powered by vBulletin® Version 3.8.11
Copyright ©2000 - 2024, vBulletin Solutions Inc.
Search Engine Optimisation provided by DragonByte SEO (Lite) - vBulletin Mods & Addons Copyright © 2024 DragonByte Technologies Ltd.
MSOfficeForums.com is not affiliated with Microsoft