![]() |
![]() | ![]() | ![]() | ![]() | ![]() | ![]() | ![]() |
| Welcome to Windows Vista Forums. Our forum is dedicated to helping you find solutions with any problems, errors or issues you are experiencing with Windows Vista. The Vista forum also covers news and updates and has an extensive Windows Vista tutorial section that covers a wide range of tips and tricks. |
| |||||||
![]() |
| |
| | #1 (permalink) |
| | VBS MailMerge Not Merging Hi all, I've got a data source on a remote server. The Function I wrote seems to be opening the data source, but the actual merge is not happening. So I end up with a document with the merge fields showing. No error msg returned. The data source file looks like this: 1~2~3~4~5~6~7~8~9~10~11~12~13~14~15~16~17~18~19~20~21~22~23~24~25~26~27~28~29~30~31 October 21, 2009~MS. SHIRLEY NAME~Her Addr Here~PHOENIX, AZ zip_here~~~~data here~more data~person's name~01-number_here~OP-2009- num_here~09/10/2009~01:42~ $11,111.00 ~Person's Name again~-------- ~6212~stuff~stuff~text here ~text~2009-numeric_here~~ $1,111.00 ~~numeric here ~acct # here~07/25/2009~~final text here And the Function I created is here: Function getFastMerge(params) Dim doc, TNUM Set doc = Word.ActiveDocument const wdSendToNewDocument = 0 const wdDefaultFirstRecord = 0 const wdDefaultLastRecord = -16 const wdOpenFormatAuto = 0 const wdMergeSubTypeOther = 0 TNUM=params(0,0) On Error Resume Next doc.MailMerge.OpenDataSource "\\svonfs\das01_exports\sdOffice \MergeData" & Cstr(TNUM) & "mrg",,True,True ' NOTE: When I recorded a macro in Word this is what it came up with, but if I try to use this, then ' I get a 'property or method not supported' msg. So this is remarked just to show params ==> ' ' ActiveDocument.MailMerge.OpenDataSource Name:= _ ' "\\svonfs\das01_exports\sdOffice\MergeDataT2161.mrg", ConfirmConversions _ ' :=False, ReadOnly:=False, LinkToSource:=True, AddToRecentFiles:=False, _ ' PasswordDocument:="", PasswordTemplate:="", WritePasswordDocument:="", _ ' WritePasswordTemplate:="", Revert:=False, Format:=wdOpenFormatAuto, _ ' Connection:="", SQLStatement:="", SQLStatement1:="", SubType:= _ ' wdMergeSubTypeOther doc.MailMerge.Destination = wdSendToNewDocument doc.MailMerge.DataSource.FirstRecord = wdDefaultFirstRecord doc.MailMerge.DataSource.LastRecord = wdDefaultLastRecord doc.MailMerge.Execute If Err.Number <> 0 then getDasFastMerge = Err.Number & " " & Err.Description Exit Function Else getDasFastMerge = "we did it" End If TNUM = Nothing doc = Nothing End Function The function is returning 'we did it'. Any help would be appreciated. Thx, Cole |
My System Specs![]() |
| | #2 (permalink) |
| | Re: VBS MailMerge Not Merging VBS = vbscript You are doing VBA (Visual Basic For Applications). These are not the same thing. You need to be posting this to a Word VBA group. Of course, you might get lucky and find one of the Word experts here, but there's no sense depending on luck is there? I will suggest that you read up on error-handling. The Err object shows the error generated by the LAST line of code. Your use of "On Error Resume Next is likely to be hiding the error, hence the result you are getting: "We did it". Unlike vbscript, in VBA you can use On Error GoTo <line-label> to get this type of structure: Function getFastMerge(params) Dim doc, TNUM 'you are better off being explicit, but not important On Error Goto ErrorHandler <statements> getDasFastMerge = "we did it" 'line labels end with a colon ExitProcedure: 'clean up code goes here 'very important: you must use Set with object variables Set TNUM = Nothing Set doc = Nothing Exit Function ErrorHandler: getDasFastMerge = Err.Number & " " & Err.Description Resume ExitProcedure End Function Cole wrote: Quote: > Hi all, > > I've got a data source on a remote server. The Function I wrote seems > to be opening the data source, but the actual merge is not happening. > So I end up with a document with the merge fields showing. No error > msg returned. The data source file looks like this: > > 28~29~30~31 Quote: > October 21, 2009~MS. SHIRLEY NAME~Her Addr Here~PHOENIX, AZ > zip_here~~~~data here~more data~person's name~01-number_here~OP-2009- > num_here~09/10/2009~01:42~ $11,111.00 ~Person's Name again~-------- > ~6212~stuff~stuff~text here ~text~2009-numeric_here~~ > $1,111.00 ~~numeric here ~acct # here~07/25/2009~~final text here > > And the Function I created is here: > > Function getFastMerge(params) > > Dim doc, TNUM > > Set doc = Word.ActiveDocument > > const wdSendToNewDocument = 0 > const wdDefaultFirstRecord = 0 > const wdDefaultLastRecord = -16 > const wdOpenFormatAuto = 0 > const wdMergeSubTypeOther = 0 > > TNUM=params(0,0) > > On Error Resume Next > > doc.MailMerge.OpenDataSource "\\svonfs\das01_exports\sdOffice > \MergeData" & Cstr(TNUM) & "mrg",,True,True > > ' NOTE: When I recorded a macro in Word this is what it came up with, > but if I try to use this, then > ' I get a 'property or method not supported' msg. So this > is remarked just to show params ==> > ' > ' ActiveDocument.MailMerge.OpenDataSource Name:= _ > ' "\\svonfs\das01_exports\sdOffice\MergeDataT2161.mrg", > ConfirmConversions _ > ' :=False, ReadOnly:=False, LinkToSource:=True, > AddToRecentFiles:=False, _ > ' PasswordDocument:="", PasswordTemplate:="", > WritePasswordDocument:="", _ > ' WritePasswordTemplate:="", Revert:=False, > Format:=wdOpenFormatAuto, _ > ' Connection:="", SQLStatement:="", SQLStatement1:="", > SubType:= _ > ' wdMergeSubTypeOther > > doc.MailMerge.Destination = wdSendToNewDocument > doc.MailMerge.DataSource.FirstRecord = wdDefaultFirstRecord > doc.MailMerge.DataSource.LastRecord = wdDefaultLastRecord > doc.MailMerge.Execute > > If Err.Number <> 0 then > getDasFastMerge = Err.Number & " " & Err.Description > Exit Function > Else > getDasFastMerge = "we did it" > End If > TNUM = Nothing > doc = Nothing > End Function > > > The function is returning 'we did it'. Any help would be > appreciated. Thx, > Cole HTH, Bob Barrows |
My System Specs![]() |
| | #3 (permalink) |
| | Re: VBS MailMerge Not Merging On Oct 21, 10:57*am, "Bob Barrows" <reb01...@newsgroup> wrote: Quote: > VBS = vbscript > You are doing VBA (Visual Basic For Applications). > These are not the same thing. You need to be posting this to a Word VBA > group. Of course, you might get lucky and find one of the Word experts > here, but there's no sense depending on luck is there? > > I will suggest that you read up on error-handling. The Err object shows > the error generated by the LAST line of code. Your use of "On Error > Resume Next is likely to be hiding the error, hence the result you are > getting: "We did it". Unlike vbscript, in VBA you can use On Error GoTo > <line-label> to get this type of structure: > > Function getFastMerge(params) > Dim doc, TNUM 'you are better off being explicit, but not important > On Error Goto ErrorHandler > <statements> > getDasFastMerge = "we did it" > > 'line labels end with a colon > ExitProcedure: > * * 'clean up code goes here > * * 'very important: you must use Set with object variables > * *Set TNUM = Nothing > * *Set doc = Nothing > > * * Exit Function > > ErrorHandler: > * * getDasFastMerge = Err.Number & " " & Err.Description > * * Resume ExitProcedure > End Function > > Cole wrote: Quote: > > Hi all, Quote: > > I've got a data source on a remote server. *The Function I wrote seems > > to be opening the data source, but the actual merge is not happening. > > So I end up with a document with the merge fields showing. *No error > > msg returned. *The data source file looks like this: > 1~2~3~4~5~6~7~8~9~10~11~12~13~14~15~16~17~18~19~20~21~22~23~24~25~26~27~ > 28~29~30~31 > > > > > Quote: > > October 21, 2009~MS. SHIRLEY NAME~Her Addr Here~PHOENIX, AZ > > zip_here~~~~data here~more data~person's name~01-number_here~OP-2009- > > num_here~09/10/2009~01:42~ * $11,111.00 ~Person's Name again~-------- > > ~6212~stuff~stuff~text here * * *~text~2009-numeric_here~~ > > $1,111.00 ~~numeric here ~acct # here~07/25/2009~~final text here Quote: > > And the Function I created is here: Quote: > > Function getFastMerge(params) Quote: > > * * Dim doc, TNUM Quote: > > * * Set doc = Word.ActiveDocument Quote: > > * * const wdSendToNewDocument = 0 > > * * const wdDefaultFirstRecord = 0 > > * * const wdDefaultLastRecord = -16 > > * * const wdOpenFormatAuto = 0 > > * * const wdMergeSubTypeOther = 0 Quote: > > * * TNUM=params(0,0) Quote: > > * * On Error Resume Next Quote: > > * * doc.MailMerge.OpenDataSource "\\svonfs\das01_exports\sdOffice > > \MergeData" & Cstr(TNUM) & "mrg",,True,True Quote: > > ' NOTE: When I recorded a macro in Word this is what it came up with, > > but if I try to use this, then > > ' * * * * * *I get a 'property or method not supported' msg.. *So this > > is remarked just to show params ==> > > ' > > ' * *ActiveDocument.MailMerge.OpenDataSource Name:= _ > > ' * * * *"\\svonfs\das01_exports\sdOffice\MergeDataT2161.mrg", > > ConfirmConversions _ > > ' * * * *:=False, ReadOnly:=False, LinkToSource:=True, > > AddToRecentFiles:=False, _ > > ' * * * *PasswordDocument:="", PasswordTemplate:="", > > WritePasswordDocument:="", _ > > ' * * * *WritePasswordTemplate:="", Revert:=False, > > Format:=wdOpenFormatAuto, _ > > ' * * * *Connection:="", SQLStatement:="", SQLStatement1:="", > > SubType:= _ > > ' * * * *wdMergeSubTypeOther Quote: > > * * * * doc.MailMerge.Destination = wdSendToNewDocument > > * * * * doc.MailMerge.DataSource.FirstRecord = wdDefaultFirstRecord > > * * * * doc.MailMerge.DataSource.LastRecord = wdDefaultLastRecord > > * * * * doc.MailMerge.Execute Quote: > > * * If Err.Number <> 0 then > > getDasFastMerge = Err.Number & " " & Err.Description > > Exit Function > > * * Else > > getDasFastMerge = "we did it" > > * *End If > > * *TNUM = Nothing > > * *doc = Nothing > > End Function Quote: > > The function is returning 'we did it'. *Any help would be > > appreciated. *Thx, > > Cole > -- > HTH, > Bob Barrows- Hide quoted text - > > - Show quoted text - - Cole |
My System Specs![]() |
| | #4 (permalink) |
| | Re: VBS MailMerge Not Merging Il giorno Wed, 21 Oct 2009 07:37:35 -0700 (PDT), Cole <cole.simonson@newsgroup> ha scritto: You cannot use named arguments in vbs. Look at the syntax of these commands in Word and put the parameters in the right order. Without "NAME:=" and comma-separated. Probably the arguments are in the right order and you only have to strip off the *name* of the argument. Quote: >' I get a 'property or method not supported' msg. So this >is remarked just to show params ==> >' >' ActiveDocument.MailMerge.OpenDataSource Name:= _ >' "\\svonfs\das01_exports\sdOffice\MergeDataT2161.mrg", >ConfirmConversions _ >' :=False, ReadOnly:=False, LinkToSource:=True, >AddToRecentFiles:=False, _ >' PasswordDocument:="", PasswordTemplate:="", >WritePasswordDocument:="", _ >' WritePasswordTemplate:="", Revert:=False, >Format:=wdOpenFormatAuto, _ >' Connection:="", SQLStatement:="", SQLStatement1:="", >SubType:= _ >' wdMergeSubTypeOther ActiveDocument.MailMerge.OpenDataSource "\\svonfs\das01_exports\sdOffice\MergeDataT2161.mrg", False, False, True, False, "","", "", "", False, wdOpenFormatAuto, "", "", "", wdMergeSubTypeOther Constants like these are not defined in vbs, so you have to open the "immediate" window in the vba editor and take note of the value of ?wdSendToNewDocument Then you can use const wdSendToNewDocument= 0 const wdDefaultFirstRecord= 1 const wdDefaultLastRecord= -16 Quote: > doc.MailMerge.Destination = wdSendToNewDocument > doc.MailMerge.DataSource.FirstRecord = wdDefaultFirstRecord > doc.MailMerge.DataSource.LastRecord = wdDefaultLastRecord Giovanni Cenati (Bergamo, Italy) Write to "Reventlov" at katamail com http://digilander.libero.it/Cenati (Esempi e programmi in VbScript) -- |
My System Specs![]() |
![]() |
| Thread Tools | |
| |
Similar Threads | ||||
| Thread | Forum | |||
| Merging of csv data | PowerShell | |||
| Have to approve every mailmerge message | Live Mail | |||
Partition Merging | General Discussion | |||
| Vista compatibility with Word 2000 mailmerge | Vista General | |||