1. William Hicks
  2. PowerBuilder
  3. Monday, 29 November 2021 12:19 PM UTC

I open an existing Word document using oleobject and successfully manipulate the contents. The document is left open in Word for the user to make any further modifications and save as required. This is all ok.

I want to set the default path and file name so that if the user decides to save it they don't need to type the name and select the folder unless they want to save somewhere other than the standard location or with a different filename.

The closest thing I have found is this:

https://wordmvp.com/FAQs/MacrosVBA/SetDefFilename.htm

which I have simplified to this:

Sub chgsave()
    Set dlgProp = Dialogs(wdDialogFileSummaryInfo)
    dlgProp.Title = "myfile.docx"
    dlgProp.Execute
End Sub

I have confirmed this works as Word macro but I have not managed to successfully convert this to PB code for my oleobject. I think my problem is getting hold of the Dialog. I believe it would be possible to call a macro from PB but I don't want to use macro-enabled documents.

Thanks in advance,

William.

Accepted Answer
René Ullrich Accepted Answer Pending Moderation
  1. Monday, 29 November 2021 13:08 PM UTC
  2. PowerBuilder
  3. # Permalink

Hi William,

the PB Code is

oleobject lole_dialog
lole_dialog = ole_control.object.Application.Dialogs.Item(86) // 86 is wdDialogFileSummaryInfo
lole_dialog.Title = "myfile.docx"
lole_dialog.Execute()

But it seems only to work with new documents. If you open an existing document it uses the existing filename, but it shows the "title" (not filename!) you set in the dialog.

This is not only with PB but also in Word.

But maybe this is what you want?

oleobject lole_dialog
lole_dialog = ole_control.object.Application.Dialogs.Item(84) // 84 is wdDialogFileSaveAs
lole_dialog.Name = "myfile.docx"
lole_dialog.Execute()

Regards,

René

Comment
  1. William Hicks
  2. Monday, 29 November 2021 13:20 PM UTC
Hi René,



thank you so much. You second piece of code seems to do the trick. One thing I had not appreciated was how to access the particular dialog through Item.



Regards,



William.
  1. Helpful
There are no comments made yet.


There are replies in this question but you are not allowed to view the replies from this question.
We use cookies which are necessary for the proper functioning of our websites. We also use cookies to analyze our traffic, improve your experience and provide social media features. If you continue to use this site, you consent to our use of cookies.