View Single Post
 
Old 07-04-2014, 08:49 PM
smndnm smndnm is offline Windows 7 64bit Office 2010 32bit
Novice
 
Join Date: Jul 2014
Location: Queensland
Posts: 24
smndnm is on a distinguished road
Question 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:

  • Open and populate doc123.docx
  • Open one of the many docABC.dotm (intially and correctly as Document1.docx), which updates its links from doc123.docx
  • Click save (which would ordinarily invoke the SaveAs dialog, however...) - which automatically runs this macro:- (which forces a name and filetype change, it also directs the filesave location to a predetermined place, it also updates the Subject and Title properties) Many thanks go to Paul Edstein for most of this code.

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
My questions are:
  1. what code is required to get this macro to run at the required instant? (my confusion here is the new Document1.docx is not where the macro was saved to)
  2. Why does the changed Title property not appear in the filename dialog box? (at this stage I am forced to use .Name = StrNm which is not an issue, but perhaps is not so elegant a solution)
  3. Is the code layout correct?
Your thoughts please.
Regards from a bright and sunny Queensland.
Reply With Quote