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 -