vbams-wordribbonx

save as PDF and delete command button


im trying to create a command button in a word document that would pop up the "save as" screen to save as PDF, but i dont want the command button to save with the document. is this something i can do with a VBA?

i got as far as:

Sub Save_to_PDF()
'
' Save_to_PDF Macro
'
'
  With Dialogs(wdDialogFileSaveAs)
        .Format = wdFormatPDF
        .Show
    End With
    
End Sub

but i cant find a way to get it to delete the button as well


Solution

  • To do this you have to create a command button on the toolbar after added your VBA program to a module. Right click on the Toolbars and select Customize.

    First create a new toolbar: On the Toolbars tab click Create. Give a name and click OK. Move the created toolbar to the Toolbars.

    Change to Commands tab. In categories select Macros. At the buttom of the pane in the Location window instead of Normal.dot select the name of the Word Document where you placed your macro.

    From the right window (with leftclick-hold down) move your program's name into the toolbar which you have just created. That's all. Click and start your program.

    For Word 2007:

    Right-click the commandbar and select Customize the Ribbon. (It could be provide easier handling then the Quick Access Toolbar which will be soon full of icons)

    On the bottom of the right pane select New Tab. Rename the New Group (automatically selected) under New Tab, for the required name and click OK.

    On the top of the left pane in the "Choose Commands from:" textbox select Macros. Your macro's name appear in the listbox. Drag the name of your macro and move it over the tagname you have created.

    Close Customize Ribbon window with the bottom right OK.

    After it, on the Command Bar there is a New Tab tab. Click it and your macro name appear. Click and start it.

    To delete, select in Customize Ribbon the name you want to delete, and click Remove.