#1
|
|||
|
|||
How to invoke the macro correctly in the workflow
Hello,
I am struggling with understanding of when (and how) to invoke a macro correctly in my intended workflow. My workflow goes:
Code:
Sub Document_New() ' ' Demo Macro ' ' Dim StrNm As String Dim DocSubject As String With ActiveDocument StrNm = "SWMS " & .Bookmarks("docnumber").Range.Text & " " & _ .Bookmarks("doctype").Range.Text & " - " & _ .Bookmarks("sitename").Range.Text & " - " & _ .Bookmarks("personname").Range.Text DocSubject = .Bookmarks("doctype").Range.Text .BuiltInDocumentProperties("Title") = StrNm .BuiltInDocumentProperties("Subject") = DocSubject End With With Application.Dialogs(wdDialogFileSaveAs) .Name = StrNm .Format = wdFormatPDF Options.DefaultFilePath(wdDocumentsPath) = "C:\folderA\folderb .Show End With End Sub
Regards from a bright and sunny Queensland. |
#2
|
||||
|
||||
Re 1: That depends on what determines the required instant. As coded, the macro runs to completion when the document is created. Depending on what you want to do between opening and saving the document, it might be possible to solicit any required inputs via an InputBox, or two, for example, or by working with other dialogues. That way, the macro merely suspends processing while waiting for the required inputs.
Re 2: I don't see what the issue is. Since you're populating the title with the contents of the StrNm variable, there is no reason to not continue using it for whatever else it might be useful for. That said, if you're desperate to refer to the title property, you could use: .Name = ActiveDocument.BuiltInDocumentProperties("Title") Re: 3: The layout looks fine, though I'd be inclined to indent the .BuiltInDocumentProperties references so the nesting of the structure remains more apparent. The main point in using such visible structuring is for ease of maintenance. FWIW, though, VBA really doesn't care how the code looks - it's the logical structure that matters. Also, rather than creating and using 'DocSubject' for a once-off use, I'd be inclined to use: .BuiltInDocumentProperties("Subject") = .Bookmarks("doctype").Range.Text
__________________
Cheers, Paul Edstein [Fmr MS MVP - Word] |
#3
|
|||
|
|||
Re: Re1 Apologies, I haven't been clear here: When the docABC.dotm opens (by double click), a dialogue box opens confirming whether to updates the links (I am happy to leave this as a manual update for now, but I will pursue the code to make it automatic) THEN the user clicks save (otherwise the bookmarks won't be updated correctly); the macro now runs as described (-ish??). The question stills remains on how to invoke the macro at this time. Is it supposed to be "Sub Document_save()" ?
Re: Re2 The issue stems from my limited understanding that Word's default behaviour is to suggest the filename from the Title Property, my thinking is to use default behaviours to acheive my aims, but it makes little difference to the outcome.. However, I do want the properties to translate across to the (protected) pdf. There should be no doubt about who's pdf document it is. (I'll add some code to correctly protect the pdf) Re: Re3 Thank you for this, the more I look at your suggestions, the better I see how the code works and then how I can make it work for me. I'll post the next iteration of the macro later today. Regards from a bright sunny, albeit a little chilly (for us softies) Queensland |
#4
|
||||
|
||||
Re 1: The updating of links could be incorporated into the code, so there are no alerts/prompts. It's also possible to include any bookmark updates.
Re 2: If you'd checked a PDF file created using the code I gave you, you'd see that it has the title data. PS: Still -1C here @ 9:30am
__________________
Cheers, Paul Edstein [Fmr MS MVP - Word] |
#5
|
|||
|
|||
The macro works when run from within the whateveritscalled=AltF11 environment. But the workflow is still broken. The filename and filetype changes do not occur on clicking the save icon.
While I understand the code I am looking at (or at least it makes sense). I don't get how or when it gets invoked or even how to make that happen on my say so. From the XXX.dotm, when I open (double click) it to a document1.docx, this macro should be invoked upon clicking the Save icon, which would perform the filetype and filename and location changes, this part doesn't work... and I am completely clueless how to even begin looking at it. The macro works, the invocation doesn't. I am not looking to be provided with the solution but rather guidance on where/how to find the answers. Your thoughts please. Regards from balmy Queensland |
#6
|
||||
|
||||
Quote:
Quote:
Quote:
Quote:
FileSaveAs and add another macro: Code:
Sub FileSave Call FileSaveAs End Sub
__________________
Cheers, Paul Edstein [Fmr MS MVP - Word] |
#7
|
|||
|
|||
And now it works... and I am left none the wiser as to why or how. My partner calls this "drowning while reading a book on swimming".
I'll be reading the beginner books mentioned in another thread on this site Thank you so much for helping, your knowledge and patience are appreciated. Regards from a warmer place than yours |
|
Similar Threads | ||||
Thread | Thread Starter | Forum | Replies | Last Post |
Suggestions wanted for improving workflow of shared incoming emails | plaidma1 | Outlook | 1 | 05-03-2013 09:33 AM |
How to add a file menu item and invoke an EXE? | simplyarun | PowerPoint | 0 | 07-21-2011 01:59 AM |
margins don't set correctly | dawit | Word | 1 | 05-10-2011 09:47 PM |
TOC Not Updating Correctly | Nigel1985 | Word | 1 | 05-27-2010 07:19 PM |
workflow | silviu | Office | 1 | 05-21-2009 11:12 AM |