0

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

Eugene Astafiev
  • 47,483
  • 3
  • 24
  • 45
  • Your question shows the display of a userform that I imagine could be triggered from an ActiveX control on the document. See the second answer on this page to delete an ActiveX command button with VBA: https://stackoverflow.com/questions/755247/how-do-i-delete-a-command-button-using-word-vba – John Korchok Apr 22 '23 at 23:18

2 Answers2

0

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.

Black cat
  • 1,056
  • 1
  • 2
  • 11
0

Typically you may assign a QAT button to a macro. See Assign a macro to a button.

Note, command bars were deprecated. You need to use the Fluent UI for customizing the ribbon. If you don't want to save your customizations to any specific Word document you may consider creating a COM add-in for that. Otherwise, you can create a custom ribbon UI with your button assigned to a VBA macro by creating a *.docm document. Read more about the Fluent UI (aka Ribbon UI) in the following articles:

Eugene Astafiev
  • 47,483
  • 3
  • 24
  • 45