Community
Showing results for 
Search instead for 
Do you mean 
Reply

Running AutoNew macro/ getting created document handle

Tuned Listener
Posts: 15
Country: United_Kingdom

Running AutoNew macro/ getting created document handle

Word 2010 will automatically run the AutoNew macro when a new document is created from a template. If I include an AutoNew macro in the .adt file, then AutoNew macro is not getting executed.

 

Is there one of the following solutions?

 

1) ACT WriteOther triggers the AutoNew macro in MS Word.

2) ACT returns a handle to the Word document, so that I can programatically force a macro to run.

 

Any help appreciated.

Cheers

Richard

 

Bronze Super Contributor
Posts: 1,231
Country: USA

Re: Running AutoNew macro/ getting created document handle

What functions are in the autonew macro? Why not move those functions to code?

 

-- Jim Durkin

Tuned Listener
Posts: 15
Country: United_Kingdom

Re: Running AutoNew macro/ getting created document handle

Because to trigger the code, you need to have access to the document itself (hence my secondary query about obtaining the document handle) and be able to confirm that the document has loaded, that ACT has completed its mailmerge of data into the document, etc.

 

WriteOther does not return a link to the created document, but I can bypass this requirement if the AutoNew macro executes; it can perform the actions I require without needing to code it within the ACT plugin.

 

As far as I can see (and the documentation for coding in ACT is appalling!), UICorrespondenceManager creates documents on a "fire-and-forget" model. Unfortunately to do anything useful, you then need to control the document (eg. "save as" to a specific location, create a link in ACT.history to the document, etc.)

 

Bottom line is: to do anything useful you need to access the specific document created (you may already have other documents open). If ACT cannot provide this information, then I need the AutoNew macro to run.

 

Cheers

Richard

 

Bronze Super Contributor
Posts: 1,231
Country: USA

Re: Running AutoNew macro/ getting created document handle

I have never used the UICorrespondenceManager.

We always create our own word document then use the CreateHistory function to attached the document to a contact.

 

 Public Function DocumentAttach(ByVal cContact As Act.Framework.Contacts.Contact, _
                                 ByVal sDocumentName As String, _
                                 ByVal sDisplayName As String) As Act.Framework.SupplementalFiles.Attachment
        Try

            '-------------------------------------------------------
            ' create a temp attachment
            '-------------------------------------------------------
            Dim tmpAttachment As Act.Framework.SupplementalFiles.Attachment
            tmpAttachment = Me.HostFramework.SupplementalFileManager.CreateAttachment(SupplementalFiles.AttachmentMate.History, sDocumentName, sDisplayName, False)

            '-------------------------------------------------------
            ' This next line attaches the tmpAttachment to the cContact
            ' It does not create a history under the history tab
            '-------------------------------------------------------
            Me.HostFramework.Histories.CreateHistory(cContact, _
                      Guid.Empty, _
                      New Act.Framework.Histories.HistoryType(Act.Framework.Histories.SystemHistoryType.Library), _
                      False, _
                      DateTime.Now, _
                      DateTime.Now, _
                      tmpAttachment.FileName, _
                      String.Empty, _
                      tmpAttachment)

            Return tmpAttachment

        Catch ex As System.Exception
            LogError.Write(ex, "MergeTemplate:AttachDocument")
        End Try
    End Function

 

 

-- Jim Durkin

Tuned Listener
Posts: 15
Country: United_Kingdom

Re: Running AutoNew macro/ getting created document handle

OK. Thanks for the code... solving a problem I dont have Smiley Very Happy

 

If I create the word document manually, I suppose I can do a manual mailmerge of the contact details. Pity that ACT doesnt appear to support decent document controls in its UICorrespondenceManager, and breaks the MS Word auto-macros.

 

Anyone else have any input about getting auto-macros to work in ACT?

 

Cheers

Richard