Microsoft Office Forums

Go Back   Microsoft Office Forums > >

Reply
 
Thread Tools Display Modes
  #1  
Old 07-04-2014, 08:49 PM
smndnm smndnm is offline How to invoke the macro correctly in the workflow Windows 7 64bit How to invoke the macro correctly in the workflow Office 2010 32bit
Novice
How to invoke the macro correctly in the workflow
 
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
  #2  
Old 07-06-2014, 03:25 AM
macropod's Avatar
macropod macropod is offline How to invoke the macro correctly in the workflow Windows 7 32bit How to invoke the macro correctly in the workflow Office 2010 32bit
Administrator
 
Join Date: Dec 2010
Location: Canberra, Australia
Posts: 21,963
macropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond repute
Default

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]
Reply With Quote
  #3  
Old 07-06-2014, 03:55 PM
smndnm smndnm is offline How to invoke the macro correctly in the workflow Windows 7 64bit How to invoke the macro correctly in the workflow Office 2010 32bit
Novice
How to invoke the macro correctly in the workflow
 
Join Date: Jul 2014
Location: Queensland
Posts: 24
smndnm is on a distinguished road
Default

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
Reply With Quote
  #4  
Old 07-06-2014, 04:31 PM
macropod's Avatar
macropod macropod is offline How to invoke the macro correctly in the workflow Windows 7 32bit How to invoke the macro correctly in the workflow Office 2010 32bit
Administrator
 
Join Date: Dec 2010
Location: Canberra, Australia
Posts: 21,963
macropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond repute
Default

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]
Reply With Quote
  #5  
Old 07-07-2014, 11:44 PM
smndnm smndnm is offline How to invoke the macro correctly in the workflow Windows 7 64bit How to invoke the macro correctly in the workflow Office 2010 32bit
Novice
How to invoke the macro correctly in the workflow
 
Join Date: Jul 2014
Location: Queensland
Posts: 24
smndnm is on a distinguished road
Default

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
Reply With Quote
  #6  
Old 07-08-2014, 02:50 AM
macropod's Avatar
macropod macropod is offline How to invoke the macro correctly in the workflow Windows 7 32bit How to invoke the macro correctly in the workflow Office 2010 32bit
Administrator
 
Join Date: Dec 2010
Location: Canberra, Australia
Posts: 21,963
macropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond repute
Default

Quote:
Originally Posted by smndnm View Post
The macro works when run from within the whateveritscalled=AltF11 environment. But the workflow is still broken.
If you had added the macro to the document template's 'ThisDocument' code module, it would run immediately the document is created. As for Alt-F11, have you never used Alt-F8?
Quote:
The filename and filetype changes do not occur on clicking the save icon.
The macro has nothing to do with the normal Save or SaveAs processes. As coded, it handles all the name & type definitions with it's own call to the SaveAs process. If you wanted to employ the same process for a subsequent save, it's simply a matter of running the same macro again.
Quote:
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.
It runs automatically and you can run it manually.
Quote:
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.
because that's not how the macro works. If all you want is to intercept the SaveAs and Save commands, simply rename the macro:
FileSaveAs
and add another macro:
Code:
Sub FileSave
Call FileSaveAs
End Sub
__________________
Cheers,
Paul Edstein
[Fmr MS MVP - Word]
Reply With Quote
  #7  
Old 07-08-2014, 03:13 AM
smndnm smndnm is offline How to invoke the macro correctly in the workflow Windows 7 64bit How to invoke the macro correctly in the workflow Office 2010 32bit
Novice
How to invoke the macro correctly in the workflow
 
Join Date: Jul 2014
Location: Queensland
Posts: 24
smndnm is on a distinguished road
Default

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
Reply With Quote
Reply



Similar Threads
Thread Thread Starter Forum Replies Last Post
How to invoke the macro correctly in the workflow 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
How to invoke the macro correctly in the workflow margins don't set correctly dawit Word 1 05-10-2011 09:47 PM
How to invoke the macro correctly in the workflow TOC Not Updating Correctly Nigel1985 Word 1 05-27-2010 07:19 PM
How to invoke the macro correctly in the workflow workflow silviu Office 1 05-21-2009 11:12 AM

Other Forums: Access Forums

All times are GMT -7. The time now is 04:04 AM.


Powered by vBulletin® Version 3.8.11
Copyright ©2000 - 2024, vBulletin Solutions Inc.
Search Engine Optimisation provided by DragonByte SEO (Lite) - vBulletin Mods & Addons Copyright © 2024 DragonByte Technologies Ltd.
MSOfficeForums.com is not affiliated with Microsoft