Ok usually I would just take my time and try to figure this out on my
own but time is short and I willing admit I am way out of my league.
I found the code on gmayor.com for splitting mail merges. The macro
works to the extent that it will give the first record but then errors
out with Object variable or With block variable not set. Does anyone
see what is obviously wrong here? And a side question is how do I get
these to be saved as .pdf files?

Thanks in advance for any help

Sub SplitMergeLetter()
' splitter Macro modified to save individual letters with
' information from data source. The filename data must be added to
' the top of the merge letter - see web article.

Selection.EndKey Unit:=wdStory
Letters = Selection.Information(wdActiveEndSectionNumber)
Selection.HomeKey Unit:=wdStory
Counter = 1
While Counter < Letters
Application.ScreenUpdating = False
With Selection
.HomeKey Unit:=wdStory
.EndKey Unit:=wdLine, Extend:=wdExtend
.MoveLeft Unit:=wdCharacter, Count:=1, Extend:=wdExtend
End With
sName = Selection
Docname = "F:\Test\" & sName & ".doc"
ActiveDocument.Sections.First.Range.Cut
Documents.Add
With Selection
.Paste
.HomeKey Unit:=wdStory
.MoveDown Unit:=wdLine, Count:=1, Extend:=wdExtend
.Delete
End With
ActiveDocument.SaveAs FileName:=Docname, _
FileFormat:=wdFormatDocument
ActiveWindow.Close
Counter = Counter + 1
Application.ScreenUpdating = True
Wend
End Sub

Re: Object variable or With block variable not set error in macro by Doug

Doug
Mon Jan 14 12:05:14 PST 2008

Are you running the macro on a document created by executing the mail merge
to a new document? If so, what line of code is highlighted when you get the
error message.

To create .pdf files, after the line that saves each file, and before the
active document is closed, you would have to include a command to print out
the file to a .pdf printer.

--
Hope this helps.

Please reply to the newsgroup unless you wish to avail yourself of my
services on a paid consulting basis.

Doug Robbins - Word MVP

<cuppless@gmail.com> wrote in message
news:066a3a82-3241-4dd7-81f2-c9b08d0d0663@n20g2000hsh.googlegroups.com...
> Ok usually I would just take my time and try to figure this out on my
> own but time is short and I willing admit I am way out of my league.
> I found the code on gmayor.com for splitting mail merges. The macro
> works to the extent that it will give the first record but then errors
> out with Object variable or With block variable not set. Does anyone
> see what is obviously wrong here? And a side question is how do I get
> these to be saved as .pdf files?
>
> Thanks in advance for any help
>
> Sub SplitMergeLetter()
> ' splitter Macro modified to save individual letters with
> ' information from data source. The filename data must be added to
> ' the top of the merge letter - see web article.
>
> Selection.EndKey Unit:=wdStory
> Letters = Selection.Information(wdActiveEndSectionNumber)
> Selection.HomeKey Unit:=wdStory
> Counter = 1
> While Counter < Letters
> Application.ScreenUpdating = False
> With Selection
> .HomeKey Unit:=wdStory
> .EndKey Unit:=wdLine, Extend:=wdExtend
> .MoveLeft Unit:=wdCharacter, Count:=1, Extend:=wdExtend
> End With
> sName = Selection
> Docname = "F:\Test\" & sName & ".doc"
> ActiveDocument.Sections.First.Range.Cut
> Documents.Add
> With Selection
> .Paste
> .HomeKey Unit:=wdStory
> .MoveDown Unit:=wdLine, Count:=1, Extend:=wdExtend
> .Delete
> End With
> ActiveDocument.SaveAs FileName:=Docname, _
> FileFormat:=wdFormatDocument
> ActiveWindow.Close
> Counter = Counter + 1
> Application.ScreenUpdating = True
> Wend
> End Sub



Re: Object variable or With block variable not set error in macro by cuppless

cuppless
Mon Jan 14 12:24:51 PST 2008

I am running the macro on a document that has already had the mail
merge executed. There aren't any lines highlighted which is why I am
so confused. Would it be better to run it another way?

Thanks,
Sallie



On Jan 14, 3:05=A0pm, "Doug Robbins - Word MVP"
<d...@REMOVECAPSmvps.org> wrote:
> Are you running the macro on a document created by executing the mail merg=
e
> to a new document? =A0If so, what line of code is highlighted when you get=
the
> error message.
>
> To create .pdf files, after the line that saves each file, and before the
> active document is closed, you would have to include a command to print ou=
t
> the file to a .pdf printer.
>
> --
> Hope this helps.
>
> Please reply to the newsgroup unless you wish to avail yourself of my
> services on a paid consulting basis.
>
> Doug Robbins - Word MVP
>
> <cuppl...@gmail.com> wrote in message
>
> news:066a3a82-3241-4dd7-81f2-c9b08d0d0663@n20g2000hsh.googlegroups.com...
>
>
>
> > Ok usually I would just take my time and try to figure this out on my
> > own but time is short and I willing admit I am way out of my league.
> > I found the code on gmayor.com for splitting mail merges. =A0The macro
> > works to the extent that it will give the first record but then errors
> > out with Object variable or With block variable not set. =A0Does anyone
> > see what is obviously wrong here? =A0And a side question is how do I get=

> > these to be saved as .pdf files?
>
> > Thanks in advance for any help
>
> > Sub SplitMergeLetter()
> > ' splitter Macro modified to save individual letters with
> > ' information from data source. The filename data must be added to
> > ' the top of the merge letter - see web article.
>
> > Selection.EndKey Unit:=3DwdStory
> > Letters =3D Selection.Information(wdActiveEndSectionNumber)
> > Selection.HomeKey Unit:=3DwdStory
> > Counter =3D 1
> > While Counter < Letters
> > =A0 =A0Application.ScreenUpdating =3D False
> > =A0 =A0With Selection
> > =A0 =A0 =A0 =A0.HomeKey Unit:=3DwdStory
> > =A0 =A0 =A0 =A0.EndKey Unit:=3DwdLine, Extend:=3DwdExtend
> > =A0 =A0 =A0 =A0.MoveLeft Unit:=3DwdCharacter, Count:=3D1, Extend:=3DwdEx=
tend
> > =A0 =A0End With
> > =A0 =A0sName =3D Selection
> > =A0 =A0Docname =3D "F:\Test\" & sName & ".doc"
> > =A0 =A0ActiveDocument.Sections.First.Range.Cut
> > =A0 =A0Documents.Add
> > =A0 =A0With Selection
> > =A0 =A0 =A0 =A0.Paste
> > =A0 =A0 =A0 =A0.HomeKey Unit:=3DwdStory
> > =A0 =A0 =A0 =A0.MoveDown Unit:=3DwdLine, Count:=3D1, Extend:=3DwdExtend
> > =A0 =A0 =A0 =A0.Delete
> > =A0 =A0End With
> > =A0 =A0ActiveDocument.SaveAs FileName:=3DDocname, _
> > =A0 =A0FileFormat:=3DwdFormatDocument
> > =A0 =A0ActiveWindow.Close
> > =A0 =A0Counter =3D Counter + 1
> > =A0 =A0Application.ScreenUpdating =3D True
> > Wend
> > End Sub- Hide quoted text -
>
> - Show quoted text -


Re: Object variable or With block variable not set error in macro by Doug

Doug
Mon Jan 14 15:11:55 PST 2008

But was the document on which you are running the macro the document that
was created by executing the mail merge to a new document?

When the error occurs, what line of code in the VBE editor is highlighted.

--
Hope this helps.

Please reply to the newsgroup unless you wish to avail yourself of my
services on a paid consulting basis.

Doug Robbins - Word MVP

<cuppless@gmail.com> wrote in message
news:4becfb92-af50-49b4-80ad-8c96f49e0a2b@v29g2000hsf.googlegroups.com...
I am running the macro on a document that has already had the mail
merge executed. There aren't any lines highlighted which is why I am
so confused. Would it be better to run it another way?

Thanks,
Sallie



On Jan 14, 3:05 pm, "Doug Robbins - Word MVP"
<d...@REMOVECAPSmvps.org> wrote:
> Are you running the macro on a document created by executing the mail
> merge
> to a new document? If so, what line of code is highlighted when you get
> the
> error message.
>
> To create .pdf files, after the line that saves each file, and before the
> active document is closed, you would have to include a command to print
> out
> the file to a .pdf printer.
>
> --
> Hope this helps.
>
> Please reply to the newsgroup unless you wish to avail yourself of my
> services on a paid consulting basis.
>
> Doug Robbins - Word MVP
>
> <cuppl...@gmail.com> wrote in message
>
> news:066a3a82-3241-4dd7-81f2-c9b08d0d0663@n20g2000hsh.googlegroups.com...
>
>
>
> > Ok usually I would just take my time and try to figure this out on my
> > own but time is short and I willing admit I am way out of my league.
> > I found the code on gmayor.com for splitting mail merges. The macro
> > works to the extent that it will give the first record but then errors
> > out with Object variable or With block variable not set. Does anyone
> > see what is obviously wrong here? And a side question is how do I get
> > these to be saved as .pdf files?
>
> > Thanks in advance for any help
>
> > Sub SplitMergeLetter()
> > ' splitter Macro modified to save individual letters with
> > ' information from data source. The filename data must be added to
> > ' the top of the merge letter - see web article.
>
> > Selection.EndKey Unit:=wdStory
> > Letters = Selection.Information(wdActiveEndSectionNumber)
> > Selection.HomeKey Unit:=wdStory
> > Counter = 1
> > While Counter < Letters
> > Application.ScreenUpdating = False
> > With Selection
> > .HomeKey Unit:=wdStory
> > .EndKey Unit:=wdLine, Extend:=wdExtend
> > .MoveLeft Unit:=wdCharacter, Count:=1, Extend:=wdExtend
> > End With
> > sName = Selection
> > Docname = "F:\Test\" & sName & ".doc"
> > ActiveDocument.Sections.First.Range.Cut
> > Documents.Add
> > With Selection
> > .Paste
> > .HomeKey Unit:=wdStory
> > .MoveDown Unit:=wdLine, Count:=1, Extend:=wdExtend
> > .Delete
> > End With
> > ActiveDocument.SaveAs FileName:=Docname, _
> > FileFormat:=wdFormatDocument
> > ActiveWindow.Close
> > Counter = Counter + 1
> > Application.ScreenUpdating = True
> > Wend
> > End Sub- Hide quoted text -
>
> - Show quoted text -



Re: Object variable or With block variable not set error in macro by cuppless

cuppless
Mon Jan 14 17:31:51 PST 2008

Yes the document I am running the macro on is the document created by
executing the mail merge to a new document.

No lines of code in the VBE editor are highlighted.



On Jan 14, 6:11=A0pm, "Doug Robbins - Word MVP"
<d...@REMOVECAPSmvps.org> wrote:
> But was the document on which you are running the macro the document that
> was created by executing the mail merge to a new document?
>
> When the error occurs, what line of code in the VBE editor is highlighted.=

>
> --
> Hope this helps.
>
> Please reply to the newsgroup unless you wish to avail yourself of my
> services on a paid consulting basis.
>
> Doug Robbins - Word MVP
>
> <cuppl...@gmail.com> wrote in message
>
> news:4becfb92-af50-49b4-80ad-8c96f49e0a2b@v29g2000hsf.googlegroups.com...
> I am running the macro on a document that has already had the mail
> merge executed. =A0There aren't any lines highlighted which is why I am
> so confused. =A0Would it be better to run it another way?
>
> Thanks,
> Sallie
>
> On Jan 14, 3:05 pm, "Doug Robbins - Word MVP"
>
>
>
> <d...@REMOVECAPSmvps.org> wrote:
> > Are you running the macro on a document created by executing the mail
> > merge
> > to a new document? If so, what line of code is highlighted when you get
> > the
> > error message.
>
> > To create .pdf files, after the line that saves each file, and before th=
e
> > active document is closed, you would have to include a command to print
> > out
> > the file to a .pdf printer.
>
> > --
> > Hope this helps.
>
> > Please reply to the newsgroup unless you wish to avail yourself of my
> > services on a paid consulting basis.
>
> > Doug Robbins - Word MVP
>
> > <cuppl...@gmail.com> wrote in message
>
> >news:066a3a82-3241-4dd7-81f2-c9b08d0d0663@n20g2000hsh.googlegroups.com...=

>
> > > Ok usually I would just take my time and try to figure this out on my
> > > own but time is short and I willing admit I am way out of my league.
> > > I found the code on gmayor.com for splitting mail merges. The macro
> > > works to the extent that it will give the first record but then errors=

> > > out with Object variable or With block variable not set. Does anyone
> > > see what is obviously wrong here? And a side question is how do I get
> > > these to be saved as .pdf files?
>
> > > Thanks in advance for any help
>
> > > Sub SplitMergeLetter()
> > > ' splitter Macro modified to save individual letters with
> > > ' information from data source. The filename data must be added to
> > > ' the top of the merge letter - see web article.
>
> > > Selection.EndKey Unit:=3DwdStory
> > > Letters =3D Selection.Information(wdActiveEndSectionNumber)
> > > Selection.HomeKey Unit:=3DwdStory
> > > Counter =3D 1
> > > While Counter < Letters
> > > Application.ScreenUpdating =3D False
> > > With Selection
> > > .HomeKey Unit:=3DwdStory
> > > .EndKey Unit:=3DwdLine, Extend:=3DwdExtend
> > > .MoveLeft Unit:=3DwdCharacter, Count:=3D1, Extend:=3DwdExtend
> > > End With
> > > sName =3D Selection
> > > Docname =3D "F:\Test\" & sName & ".doc"
> > > ActiveDocument.Sections.First.Range.Cut
> > > Documents.Add
> > > With Selection
> > > .Paste
> > > .HomeKey Unit:=3DwdStory
> > > .MoveDown Unit:=3DwdLine, Count:=3D1, Extend:=3DwdExtend
> > > .Delete
> > > End With
> > > ActiveDocument.SaveAs FileName:=3DDocname, _
> > > FileFormat:=3DwdFormatDocument
> > > ActiveWindow.Close
> > > Counter =3D Counter + 1
> > > Application.ScreenUpdating =3D True
> > > Wend
> > > End Sub- Hide quoted text -
>
> > - Show quoted text -- Hide quoted text -
>
> - Show quoted text -


Re: Object variable or With block variable not set error in macro by cuppless

cuppless
Mon Jan 14 18:54:58 PST 2008

So, I looked at the script and this is what I am seeing...

1. It looks like the while loop may not be working correctly as it
stops after the macro processes the first section in the merged word
document
2. When I run the macro manually I get the following: "Object
Variable or with variable not set", but the first section still gets
saved with the right document name to the locatioin I specified in the
macro. The other sections in the merged file havent changed.

Thoughts?



On Jan 14, 8:31=A0pm, cuppl...@gmail.com wrote:
> Yes the document I am running the macro on is the document created by
> executing the mail merge to a new document.
>
> No lines of code in the VBE editor are highlighted.
>
> On Jan 14, 6:11=A0pm, "Doug Robbins - Word MVP"
>
>
>
> <d...@REMOVECAPSmvps.org> wrote:
> > But was the document on which you are running the macro the document tha=
t
> > was created by executing the mail merge to a new document?
>
> > When the error occurs, what line of code in the VBE editor is highlighte=
d.
>
> > --
> > Hope this helps.
>
> > Please reply to the newsgroup unless you wish to avail yourself of my
> > services on a paid consulting basis.
>
> > Doug Robbins - Word MVP
>
> > <cuppl...@gmail.com> wrote in message
>
> >news:4becfb92-af50-49b4-80ad-8c96f49e0a2b@v29g2000hsf.googlegroups.com...=

> > I am running the macro on a document that has already had the mail
> > merge executed. =A0There aren't any lines highlighted which is why I am
> > so confused. =A0Would it be better to run it another way?
>
> > Thanks,
> > Sallie
>
> > On Jan 14, 3:05 pm, "Doug Robbins - Word MVP"
>
> > <d...@REMOVECAPSmvps.org> wrote:
> > > Are you running the macro on a document created by executing the mail
> > > merge
> > > to a new document? If so, what line of code is highlighted when you ge=
t
> > > the
> > > error message.
>
> > > To create .pdf files, after the line that saves each file, and before =
the
> > > active document is closed, you would have to include a command to prin=
t
> > > out
> > > the file to a .pdf printer.
>
> > > --
> > > Hope this helps.
>
> > > Please reply to the newsgroup unless you wish to avail yourself of my
> > > services on a paid consulting basis.
>
> > > Doug Robbins - Word MVP
>
> > > <cuppl...@gmail.com> wrote in message
>
> > >news:066a3a82-3241-4dd7-81f2-c9b08d0d0663@n20g2000hsh.googlegroups.com.=
..
>
> > > > Ok usually I would just take my time and try to figure this out on m=
y
> > > > own but time is short and I willing admit I am way out of my league.=

> > > > I found the code on gmayor.com for splitting mail merges. The macro
> > > > works to the extent that it will give the first record but then erro=
rs
> > > > out with Object variable or With block variable not set. Does anyone=

> > > > see what is obviously wrong here? And a side question is how do I ge=
t
> > > > these to be saved as .pdf files?
>
> > > > Thanks in advance for any help
>
> > > > Sub SplitMergeLetter()
> > > > ' splitter Macro modified to save individual letters with
> > > > ' information from data source. The filename data must be added to
> > > > ' the top of the merge letter - see web article.
>
> > > > Selection.EndKey Unit:=3DwdStory
> > > > Letters =3D Selection.Information(wdActiveEndSectionNumber)
> > > > Selection.HomeKey Unit:=3DwdStory
> > > > Counter =3D 1
> > > > While Counter < Letters
> > > > Application.ScreenUpdating =3D False
> > > > With Selection
> > > > .HomeKey Unit:=3DwdStory
> > > > .EndKey Unit:=3DwdLine, Extend:=3DwdExtend
> > > > .MoveLeft Unit:=3DwdCharacter, Count:=3D1, Extend:=3DwdExtend
> > > > End With
> > > > sName =3D Selection
> > > > Docname =3D "F:\Test\" & sName & ".doc"
> > > > ActiveDocument.Sections.First.Range.Cut
> > > > Documents.Add
> > > > With Selection
> > > > .Paste
> > > > .HomeKey Unit:=3DwdStory
> > > > .MoveDown Unit:=3DwdLine, Count:=3D1, Extend:=3DwdExtend
> > > > .Delete
> > > > End With
> > > > ActiveDocument.SaveAs FileName:=3DDocname, _
> > > > FileFormat:=3DwdFormatDocument
> > > > ActiveWindow.Close
> > > > Counter =3D Counter + 1
> > > > Application.ScreenUpdating =3D True
> > > > Wend
> > > > End Sub- Hide quoted text -
>
> > > - Show quoted text -- Hide quoted text -
>
> > - Show quoted text -- Hide quoted text -
>
> - Show quoted text

Re: Object variable or With block variable not set error in macro by Doug

Doug
Mon Jan 14 18:53:21 PST 2008

If you want to send the document (or several sections of it) to me at
dkr@mvps.org I will take a look at it.

--
Hope this helps.

Please reply to the newsgroup unless you wish to avail yourself of my
services on a paid consulting basis.

Doug Robbins - Word MVP

<cuppless@gmail.com> wrote in message
news:ec015535-02ac-43d4-9f9e-69e8f030e7a6@s19g2000prg.googlegroups.com...
Yes the document I am running the macro on is the document created by
executing the mail merge to a new document.

No lines of code in the VBE editor are highlighted.



On Jan 14, 6:11 pm, "Doug Robbins - Word MVP"
<d...@REMOVECAPSmvps.org> wrote:
> But was the document on which you are running the macro the document that
> was created by executing the mail merge to a new document?
>
> When the error occurs, what line of code in the VBE editor is highlighted.
>
> --
> Hope this helps.
>
> Please reply to the newsgroup unless you wish to avail yourself of my
> services on a paid consulting basis.
>
> Doug Robbins - Word MVP
>
> <cuppl...@gmail.com> wrote in message
>
> news:4becfb92-af50-49b4-80ad-8c96f49e0a2b@v29g2000hsf.googlegroups.com...
> I am running the macro on a document that has already had the mail
> merge executed. There aren't any lines highlighted which is why I am
> so confused. Would it be better to run it another way?
>
> Thanks,
> Sallie
>
> On Jan 14, 3:05 pm, "Doug Robbins - Word MVP"
>
>
>
> <d...@REMOVECAPSmvps.org> wrote:
> > Are you running the macro on a document created by executing the mail
> > merge
> > to a new document? If so, what line of code is highlighted when you get
> > the
> > error message.
>
> > To create .pdf files, after the line that saves each file, and before
> > the
> > active document is closed, you would have to include a command to print
> > out
> > the file to a .pdf printer.
>
> > --
> > Hope this helps.
>
> > Please reply to the newsgroup unless you wish to avail yourself of my
> > services on a paid consulting basis.
>
> > Doug Robbins - Word MVP
>
> > <cuppl...@gmail.com> wrote in message
>
> >news:066a3a82-3241-4dd7-81f2-c9b08d0d0663@n20g2000hsh.googlegroups.com...
>
> > > Ok usually I would just take my time and try to figure this out on my
> > > own but time is short and I willing admit I am way out of my league.
> > > I found the code on gmayor.com for splitting mail merges. The macro
> > > works to the extent that it will give the first record but then errors
> > > out with Object variable or With block variable not set. Does anyone
> > > see what is obviously wrong here? And a side question is how do I get
> > > these to be saved as .pdf files?
>
> > > Thanks in advance for any help
>
> > > Sub SplitMergeLetter()
> > > ' splitter Macro modified to save individual letters with
> > > ' information from data source. The filename data must be added to
> > > ' the top of the merge letter - see web article.
>
> > > Selection.EndKey Unit:=wdStory
> > > Letters = Selection.Information(wdActiveEndSectionNumber)
> > > Selection.HomeKey Unit:=wdStory
> > > Counter = 1
> > > While Counter < Letters
> > > Application.ScreenUpdating = False
> > > With Selection
> > > .HomeKey Unit:=wdStory
> > > .EndKey Unit:=wdLine, Extend:=wdExtend
> > > .MoveLeft Unit:=wdCharacter, Count:=1, Extend:=wdExtend
> > > End With
> > > sName = Selection
> > > Docname = "F:\Test\" & sName & ".doc"
> > > ActiveDocument.Sections.First.Range.Cut
> > > Documents.Add
> > > With Selection
> > > .Paste
> > > .HomeKey Unit:=wdStory
> > > .MoveDown Unit:=wdLine, Count:=1, Extend:=wdExtend
> > > .Delete
> > > End With
> > > ActiveDocument.SaveAs FileName:=Docname, _
> > > FileFormat:=wdFormatDocument
> > > ActiveWindow.Close
> > > Counter = Counter + 1
> > > Application.ScreenUpdating = True
> > > Wend
> > > End Sub- Hide quoted text -
>
> > - Show quoted text -- Hide quoted text -
>
> - Show quoted text -



Re: Object variable or With block variable not set error in macro by Doug

Doug
Mon Jan 14 22:40:23 PST 2008

After the second line of code, insert the command

MsgBox Letters

and see what it returns.

--
Hope this helps.

Please reply to the newsgroup unless you wish to avail yourself of my
services on a paid consulting basis.

Doug Robbins - Word MVP

<cuppless@gmail.com> wrote in message
news:67ff3486-6a80-4f45-8fc9-30736e3756bb@e6g2000prf.googlegroups.com...
So, I looked at the script and this is what I am seeing...

1. It looks like the while loop may not be working correctly as it
stops after the macro processes the first section in the merged word
document
2. When I run the macro manually I get the following: "Object
Variable or with variable not set", but the first section still gets
saved with the right document name to the locatioin I specified in the
macro. The other sections in the merged file havent changed.

Thoughts?



On Jan 14, 8:31 pm, cuppl...@gmail.com wrote:
> Yes the document I am running the macro on is the document created by
> executing the mail merge to a new document.
>
> No lines of code in the VBE editor are highlighted.
>
> On Jan 14, 6:11 pm, "Doug Robbins - Word MVP"
>
>
>
> <d...@REMOVECAPSmvps.org> wrote:
> > But was the document on which you are running the macro the document
> > that
> > was created by executing the mail merge to a new document?
>
> > When the error occurs, what line of code in the VBE editor is
> > highlighted.
>
> > --
> > Hope this helps.
>
> > Please reply to the newsgroup unless you wish to avail yourself of my
> > services on a paid consulting basis.
>
> > Doug Robbins - Word MVP
>
> > <cuppl...@gmail.com> wrote in message
>
> >news:4becfb92-af50-49b4-80ad-8c96f49e0a2b@v29g2000hsf.googlegroups.com...
> > I am running the macro on a document that has already had the mail
> > merge executed. There aren't any lines highlighted which is why I am
> > so confused. Would it be better to run it another way?
>
> > Thanks,
> > Sallie
>
> > On Jan 14, 3:05 pm, "Doug Robbins - Word MVP"
>
> > <d...@REMOVECAPSmvps.org> wrote:
> > > Are you running the macro on a document created by executing the mail
> > > merge
> > > to a new document? If so, what line of code is highlighted when you
> > > get
> > > the
> > > error message.
>
> > > To create .pdf files, after the line that saves each file, and before
> > > the
> > > active document is closed, you would have to include a command to
> > > print
> > > out
> > > the file to a .pdf printer.
>
> > > --
> > > Hope this helps.
>
> > > Please reply to the newsgroup unless you wish to avail yourself of my
> > > services on a paid consulting basis.
>
> > > Doug Robbins - Word MVP
>
> > > <cuppl...@gmail.com> wrote in message
>
> > >news:066a3a82-3241-4dd7-81f2-c9b08d0d0663@n20g2000hsh.googlegroups.com...
>
> > > > Ok usually I would just take my time and try to figure this out on
> > > > my
> > > > own but time is short and I willing admit I am way out of my league.
> > > > I found the code on gmayor.com for splitting mail merges. The macro
> > > > works to the extent that it will give the first record but then
> > > > errors
> > > > out with Object variable or With block variable not set. Does anyone
> > > > see what is obviously wrong here? And a side question is how do I
> > > > get
> > > > these to be saved as .pdf files?
>
> > > > Thanks in advance for any help
>
> > > > Sub SplitMergeLetter()
> > > > ' splitter Macro modified to save individual letters with
> > > > ' information from data source. The filename data must be added to
> > > > ' the top of the merge letter - see web article.
>
> > > > Selection.EndKey Unit:=wdStory
> > > > Letters = Selection.Information(wdActiveEndSectionNumber)
> > > > Selection.HomeKey Unit:=wdStory
> > > > Counter = 1
> > > > While Counter < Letters
> > > > Application.ScreenUpdating = False
> > > > With Selection
> > > > .HomeKey Unit:=wdStory
> > > > .EndKey Unit:=wdLine, Extend:=wdExtend
> > > > .MoveLeft Unit:=wdCharacter, Count:=1, Extend:=wdExtend
> > > > End With
> > > > sName = Selection
> > > > Docname = "F:\Test\" & sName & ".doc"
> > > > ActiveDocument.Sections.First.Range.Cut
> > > > Documents.Add
> > > > With Selection
> > > > .Paste
> > > > .HomeKey Unit:=wdStory
> > > > .MoveDown Unit:=wdLine, Count:=1, Extend:=wdExtend
> > > > .Delete
> > > > End With
> > > > ActiveDocument.SaveAs FileName:=Docname, _
> > > > FileFormat:=wdFormatDocument
> > > > ActiveWindow.Close
> > > > Counter = Counter + 1
> > > > Application.ScreenUpdating = True
> > > > Wend
> > > > End Sub- Hide quoted text -
>
> > > - Show quoted text -- Hide quoted text -
>
> > - Show quoted text -- Hide quoted text -
>
> - Show quoted text



Re: Object variable or With block variable not set error in macro by cuppless

cuppless
Tue Jan 15 05:22:36 PST 2008

Hi Doug,

Sorry I did not see this last night it. The message box returned a 5
there were four rows merged. So I take that to mean the counter is
working, correct.


On Jan 15, 1:40=A0am, "Doug Robbins - Word MVP"
<d...@REMOVECAPSmvps.org> wrote:
> After the second line of code, insert the command
>
> MsgBox Letters
>
> and see what it returns.
>
> --
> Hope this helps.
>
> Please reply to the newsgroup unless you wish to avail yourself of my
> services on a paid consulting basis.
>
> Doug Robbins - Word MVP
>
> <cuppl...@gmail.com> wrote in message
>
> news:67ff3486-6a80-4f45-8fc9-30736e3756bb@e6g2000prf.googlegroups.com...
> So, I looked at the script and this is what I am seeing...
>
> 1. =A0It looks like the while loop may not be working correctly as it
> stops after the macro processes the first section in the merged word
> document
> 2. =A0When I run the macro manually I get the following: "Object
> Variable or with variable not set", but the first section still gets
> saved with the right document name to the locatioin I specified in the
> macro. =A0The other sections in the merged file havent changed.
>
> Thoughts?
>
> On Jan 14, 8:31 pm, cuppl...@gmail.com wrote:
>
>
>
> > Yes the document I am running the macro on is the document created by
> > executing the mail merge to a new document.
>
> > No lines of code in the VBE editor are highlighted.
>
> > On Jan 14, 6:11 pm, "Doug Robbins - Word MVP"
>
> > <d...@REMOVECAPSmvps.org> wrote:
> > > But was the document on which you are running the macro the document
> > > that
> > > was created by executing the mail merge to a new document?
>
> > > When the error occurs, what line of code in the VBE editor is
> > > highlighted.
>
> > > --
> > > Hope this helps.
>
> > > Please reply to the newsgroup unless you wish to avail yourself of my
> > > services on a paid consulting basis.
>
> > > Doug Robbins - Word MVP
>
> > > <cuppl...@gmail.com> wrote in message
>
> > >news:4becfb92-af50-49b4-80ad-8c96f49e0a2b@v29g2000hsf.googlegroups.com.=
..
> > > I am running the macro on a document that has already had the mail
> > > merge executed. There aren't any lines highlighted which is why I am
> > > so confused. Would it be better to run it another way?
>
> > > Thanks,
> > > Sallie
>
> > > On Jan 14, 3:05 pm, "Doug Robbins - Word MVP"
>
> > > <d...@REMOVECAPSmvps.org> wrote:
> > > > Are you running the macro on a document created by executing the mai=
l
> > > > merge
> > > > to a new document? If so, what line of code is highlighted when you
> > > > get
> > > > the
> > > > error message.
>
> > > > To create .pdf files, after the line that saves each file, and befor=
e
> > > > the
> > > > active document is closed, you would have to include a command to
> > > > print
> > > > out
> > > > the file to a .pdf printer.
>
> > > > --
> > > > Hope this helps.
>
> > > > Please reply to the newsgroup unless you wish to avail yourself of m=
y
> > > > services on a paid consulting basis.
>
> > > > Doug Robbins - Word MVP
>
> > > > <cuppl...@gmail.com> wrote in message
>
> > > >news:066a3a82-3241-4dd7-81f2-c9b08d0d0663@n20g2000hsh.googlegroups.co=
m...
>
> > > > > Ok usually I would just take my time and try to figure this out on=

> > > > > my
> > > > > own but time is short and I willing admit I am way out of my leagu=
e.
> > > > > I found the code on gmayor.com for splitting mail merges. The macr=
o
> > > > > works to the extent that it will give the first record but then
> > > > > errors
> > > > > out with Object variable or With block variable not set. Does anyo=
ne
> > > > > see what is obviously wrong here? And a side question is how do I
> > > > > get
> > > > > these to be saved as .pdf files?
>
> > > > > Thanks in advance for any help
>
> > > > > Sub SplitMergeLetter()
> > > > > ' splitter Macro modified to save individual letters with
> > > > > ' information from data source. The filename data must be added to=

> > > > > ' the top of the merge letter - see web article.
>
> > > > > Selection.EndKey Unit:=3DwdStory
> > > > > Letters =3D Selection.Information(wdActiveEndSectionNumber)
> > > > > Selection.HomeKey Unit:=3DwdStory
> > > > > Counter =3D 1
> > > > > While Counter < Letters
> > > > > Application.ScreenUpdating =3D False
> > > > > With Selection
> > > > > .HomeKey Unit:=3DwdStory
> > > > > .EndKey Unit:=3DwdLine, Extend:=3DwdExtend
> > > > > .MoveLeft Unit:=3DwdCharacter, Count:=3D1, Extend:=3DwdExtend
> > > > > End With
> > > > > sName =3D Selection
> > > > > Docname =3D "F:\Test\" & sName & ".doc"
> > > > > ActiveDocument.Sections.First.Range.Cut
> > > > > Documents.Add
> > > > > With Selection
> > > > > .Paste
> > > > > .HomeKey Unit:=3DwdStory
> > > > > .MoveDown Unit:=3DwdLine, Count:=3D1, Extend:=3DwdExtend
> > > > > .Delete
> > > > > End With
> > > > > ActiveDocument.SaveAs FileName:=3DDocname, _
> > > > > FileFormat:=3DwdFormatDocument
> > > > > ActiveWindow.Close
> > > > > Counter =3D Counter + 1
> > > > > Application.ScreenUpdating =3D True
> > > > > Wend
> > > > > End Sub- Hide quoted text -
>
> > > > - Show quoted text -- Hide quoted text -
>
> > > - Show quoted text -- Hide quoted text -
>
> > - Show quoted text- Hide quoted text -
>
> - Show quoted text -


Re: Object variable or With block variable not set error in macro by cuppless

cuppless
Tue Jan 15 12:49:47 PST 2008

I am so excited. I don't want to scare something but I think it is
working!!!

Thank you again for all your help. The writers of this code are my
heroes!!!

On Jan 15, 8:22=A0am, cuppl...@gmail.com wrote:
> Hi Doug,
>
> Sorry I did not see this last night it. The message box returned a 5
> there were four rows merged. =A0So I take that to mean the counter is
> working, correct.
>
> On Jan 15, 1:40=A0am, "Doug Robbins - Word MVP"
>
>
>
> <d...@REMOVECAPSmvps.org> wrote:
> > After the second line of code, insert the command
>
> > MsgBox Letters
>
> > and see what it returns.
>
> > --
> > Hope this helps.
>
> > Please reply to the newsgroup unless you wish to avail yourself of my
> > services on a paid consulting basis.
>
> > Doug Robbins - Word MVP
>
> > <cuppl...@gmail.com> wrote in message
>
> >news:67ff3486-6a80-4f45-8fc9-30736e3756bb@e6g2000prf.googlegroups.com...
> > So, I looked at the script and this is what I am seeing...
>
> > 1. =A0It looks like the while loop may not be working correctly as it
> > stops after the macro processes the first section in the merged word
> > document
> > 2. =A0When I run the macro manually I get the following: "Object
> > Variable or with variable not set", but the first section still gets
> > saved with the right document name to the locatioin I specified in the
> > macro. =A0The other sections in the merged file havent changed.
>
> > Thoughts?
>
> > On Jan 14, 8:31 pm, cuppl...@gmail.com wrote:
>
> > > Yes the document I am running the macro on is the document created by
> > > executing the mail merge to a new document.
>
> > > No lines of code in the VBE editor are highlighted.
>
> > > On Jan 14, 6:11 pm, "Doug Robbins - Word MVP"
>
> > > <d...@REMOVECAPSmvps.org> wrote:
> > > > But was the document on which you are running the macro the document=

> > > > that
> > > > was created by executing the mail merge to a new document?
>
> > > > When the error occurs, what line of code in the VBE editor is
> > > > highlighted.
>
> > > > --
> > > > Hope this helps.
>
> > > > Please reply to the newsgroup unless you wish to avail yourself of m=
y
> > > > services on a paid consulting basis.
>
> > > > Doug Robbins - Word MVP
>
> > > > <cuppl...@gmail.com> wrote in message
>
> > > >news:4becfb92-af50-49b4-80ad-8c96f49e0a2b@v29g2000hsf.googlegroups.co=
m...
> > > > I am running the macro on a document that has already had the mail
> > > > merge executed. There aren't any lines highlighted which is why I am=

> > > > so confused. Would it be better to run it another way?
>
> > > > Thanks,
> > > > Sallie
>
> > > > On Jan 14, 3:05 pm, "Doug Robbins - Word MVP"
>
> > > > <d...@REMOVECAPSmvps.org> wrote:
> > > > > Are you running the macro on a document created by executing the m=
ail
> > > > > merge
> > > > > to a new document? If so, what line of code is highlighted when yo=
u
> > > > > get
> > > > > the
> > > > > error message.
>
> > > > > To create .pdf files, after the line that saves each file, and bef=
ore
> > > > > the
> > > > > active document is closed, you would have to include a command to
> > > > > print
> > > > > out
> > > > > the file to a .pdf printer.
>
> > > > > --
> > > > > Hope this helps.
>
> > > > > Please reply to the newsgroup unless you wish to avail yourself of=
my
> > > > > services on a paid consulting basis.
>
> > > > > Doug Robbins - Word MVP
>
> > > > > <cuppl...@gmail.com> wrote in message
>
> > > > >news:066a3a82-3241-4dd7-81f2-c9b08d0d0663@n20g2000hsh.googlegroups.=
com...
>
> > > > > > Ok usually I would just take my time and try to figure this out =
on
> > > > > > my
> > > > > > own but time is short and I willing admit I am way out of my lea=
gue.
> > > > > > I found the code on gmayor.com for splitting mail merges. The ma=
cro
> > > > > > works to the extent that it will give the first record but then
> > > > > > errors
> > > > > > out with Object variable or With block variable not set. Does an=
yone
> > > > > > see what is obviously wrong here? And a side question is how do =
I
> > > > > > get
> > > > > > these to be saved as .pdf files?
>
> > > > > > Thanks in advance for any help
>
> > > > > > Sub SplitMergeLetter()
> > > > > > ' splitter Macro modified to save individual letters with
> > > > > > ' information from data source. The filename data must be added =
to
> > > > > > ' the top of the merge letter - see web article.
>
> > > > > > Selection.EndKey Unit:=3DwdStory
> > > > > > Letters =3D Selection.Information(wdActiveEndSectionNumber)
> > > > > > Selection.HomeKey Unit:=3DwdStory
> > > > > > Counter =3D 1
> > > > > > While Counter < Letters
> > > > > > Application.ScreenUpdating =3D False
> > > > > > With Selection
> > > > > > .HomeKey Unit:=3DwdStory
> > > > > > .EndKey Unit:=3DwdLine, Extend:=3DwdExtend
> > > > > > .MoveLeft Unit:=3DwdCharacter, Count:=3D1, Extend:=3DwdExtend
> > > > > > End With
> > > > > > sName =3D Selection
> > > > > > Docname =3D "F:\Test\" & sName & ".doc"
> > > > > > ActiveDocument.Sections.First.Range.Cut
> > > > > > Documents.Add
> > > > > > With Selection
> > > > > > .Paste
> > > > > > .HomeKey Unit:=3DwdStory
> > > > > > .MoveDown Unit:=3DwdLine, Count:=3D1, Extend:=3DwdExtend
> > > > > > .Delete
> > > > > > End With
> > > > > > ActiveDocument.SaveAs FileName:=3DDocname, _
> > > > > > FileFormat:=3DwdFormatDocument
> > > > > > ActiveWindow.Close
> > > > > > Counter =3D Counter + 1
> > > > > > Application.ScreenUpdating =3D True
> > > > > > Wend
> > > > > > End Sub- Hide quoted text -
>
> > > > > - Show quoted text -- Hide quoted text -
>
> > > > - Show quoted text -- Hide quoted text -
>
> > > - Show quoted text- Hide quoted text -
>
> > - Show quoted text -- Hide quoted text -
>
> - Show quoted text -