.... I know just enough to be dangerous, but the real danger is that I
might fall asleep and hit my head on my keyboard waiting for this code
to finish executing.
Some preliminaries: WinXP Pro, Office 2000, DDE linkage between Access
and Word mail merge docs
References used in the Access Module:
Visual Basic for Applications
Microsoft Access 9.0 Object Library
OLE Automation
Microsoft DAO 2.5/3.5 Compatibility
Now, about the code:
I have some Word mail merge docs that get fed by queries in the Access
db that contains this code. The code below successfully opens each Word
file, runs a macro within Word that merges the data to a new document,
closes/saves the new merged Word file and then does it again through
the For Next loop. It just does it REAL slowly.
The macro in Word works fast if I just open Word, open the doc and run
it. It takes about 5 seconds to merge 75-100 records. The code below
takes about 2 minutes. It takes most of its time merging from one
record to the next, not opening, saving or closing docs.
As you will be able to tell, I'm not a programmer. What am I doing
wrong, or inefficiently, etc?
Any help/advice is much appreciated.
Thanks,
Bob
Function ProduceMailMergeDocs()
ReDim myWordLocation(1 To 10) As String, myWordDocName(1 To 10) As
String, cnt(1 To 10)
Dim MSWord As Object
myWordLocation(1) = "C:\Word\Folder1\"
myWordLocation(2) = "C:\Word\Folder2\"
myWordLocation(3) = "C:\Word\Folder3\"
myWordLocation(4) = "C:\Word\Folder4\"
myWordLocation(5) = "C:\Word\Folder5\"
myWordLocation(6) = "C:\Word\Folder6\"
myWordLocation(7) = "C:\Word\Folder7\"
myWordDocName(1) = "Document1"
myWordDocName(2) = "Document2"
myWordDocName(3) = "Document3"
myWordDocName(4) = "Document4"
myWordDocName(5) = "Document5"
myWordDocName(6) = "Document6"
myWordDocName(7) = "Document7"
cnt(1) = DCount("[ProspectNo]", "AccessQuery1")
cnt(2) = DCount("[ProspectNo]", "AccessQuery2")
cnt(3) = DCount("[ProspectNo]", "AccessQuery3")
cnt(4) = DCount("[ProspectNo]", "AccessQuery4")
cnt(5) = DCount("[ProspectNo]", "AccessQuery5")
cnt(6) = DCount("[ProspectNo]", "AccessQuery6")
cnt(7) = DCount("[ProspectNo]", "AccessQuery7")
Set MSWord = CreateObject(Class:="Word.Application")
MSWord.Visible = True
MSWord.Activate
For n = 1 To 7
If cnt(n) > 0 Then
MSWord.Documents.Open FileName:=myWordLocation(n) &
myWordDocName(n) & ".doc"
MSWord.Run ("MailMerge")
MSWord.Run ("MailMerge2")
MSWord.ActiveDocument.SaveAs myWordLocation(n) &
myWordDocName(n) & " (" & cnt(n) & ")" & ".doc"
MSWord.ActiveDocument.Close
MSWord.ActiveDocument.Close SaveChanges:=wdDoNotSaveChanges
Else
End If
Next n
MSWord.Quit
End Function 2 2678
There is no obvious culprit, but mysterious things can sometimes happen with
automation. First, try stepping through the code, and see what lines have the
longest delay. If the delay is in one of your MSWord.Run lines, then for some
reason, your code in MS Word is running slower when automated. In that case,
you may have to add some sort of section/timestamp logging to the code that
runs in Word to see what part of it got slow.
On 22 Feb 2005 19:22:16 -0800, bl*******@longmire-co.com wrote: ... I know just enough to be dangerous, but the real danger is that I might fall asleep and hit my head on my keyboard waiting for this code to finish executing.
Some preliminaries: WinXP Pro, Office 2000, DDE linkage between Access and Word mail merge docs
References used in the Access Module: Visual Basic for Applications Microsoft Access 9.0 Object Library OLE Automation Microsoft DAO 2.5/3.5 Compatibility
Now, about the code:
I have some Word mail merge docs that get fed by queries in the Access db that contains this code. The code below successfully opens each Word file, runs a macro within Word that merges the data to a new document, closes/saves the new merged Word file and then does it again through the For Next loop. It just does it REAL slowly.
The macro in Word works fast if I just open Word, open the doc and run it. It takes about 5 seconds to merge 75-100 records. The code below takes about 2 minutes. It takes most of its time merging from one record to the next, not opening, saving or closing docs.
As you will be able to tell, I'm not a programmer. What am I doing wrong, or inefficiently, etc?
Any help/advice is much appreciated.
Thanks,
Bob
Function ProduceMailMergeDocs()
ReDim myWordLocation(1 To 10) As String, myWordDocName(1 To 10) As String, cnt(1 To 10) Dim MSWord As Object
myWordLocation(1) = "C:\Word\Folder1\" myWordLocation(2) = "C:\Word\Folder2\" myWordLocation(3) = "C:\Word\Folder3\" myWordLocation(4) = "C:\Word\Folder4\" myWordLocation(5) = "C:\Word\Folder5\" myWordLocation(6) = "C:\Word\Folder6\" myWordLocation(7) = "C:\Word\Folder7\"
myWordDocName(1) = "Document1" myWordDocName(2) = "Document2" myWordDocName(3) = "Document3" myWordDocName(4) = "Document4" myWordDocName(5) = "Document5" myWordDocName(6) = "Document6" myWordDocName(7) = "Document7"
cnt(1) = DCount("[ProspectNo]", "AccessQuery1") cnt(2) = DCount("[ProspectNo]", "AccessQuery2") cnt(3) = DCount("[ProspectNo]", "AccessQuery3") cnt(4) = DCount("[ProspectNo]", "AccessQuery4") cnt(5) = DCount("[ProspectNo]", "AccessQuery5") cnt(6) = DCount("[ProspectNo]", "AccessQuery6") cnt(7) = DCount("[ProspectNo]", "AccessQuery7")
Set MSWord = CreateObject(Class:="Word.Application") MSWord.Visible = True MSWord.Activate
For n = 1 To 7 If cnt(n) > 0 Then MSWord.Documents.Open FileName:=myWordLocation(n) & myWordDocName(n) & ".doc" MSWord.Run ("MailMerge") MSWord.Run ("MailMerge2") MSWord.ActiveDocument.SaveAs myWordLocation(n) & myWordDocName(n) & " (" & cnt(n) & ")" & ".doc" MSWord.ActiveDocument.Close MSWord.ActiveDocument.Close SaveChanges:=wdDoNotSaveChanges
Else End If Next n
MSWord.Quit End Function
You also might want to replace your DCount() calls with SQL count
queries. This thread has been closed and replies have been disabled. Please start a new discussion. Similar topics |
by: Xerxes |
last post by:
Hi,
I have a link in my page that allows users to download an exe file.
However, when I download and run it, it briefly displays the DOS box and
nothing happens.
In my php file, I have:
header("Content-Type: application/octet-stream");
header("Content-Disposition: atachment; filename=$filename");
header("Content-Length:...
|
by: Steve Jorgensen |
last post by:
Hi all,
I've been using scalar functions as a way to perform some complex data
transformation operations, and I've noticed that scalar functions
reaaaaalllllyyyy sloooowwwwww thiiiiiings dooooooown. I expect slow-down, of
course, and would even not be surprised at slow-downs up to a factor of, say
50:1, but I'm seeing slow-downs more like...
|
by: Suyog_Linux |
last post by:
I wish to know how the free()function knows how much memory to be
freed as we only give pointer to allocated memory as an argument to
free(). Does system use an internal variable to store allocated memory
when we use malloc().
Plz help......
|
by: Vinod Patel |
last post by:
I have a piece of code : -
void *data;
......
/* data initialized */
......
struct known_struct *var = (struct known_struct*) data; /*typecasting*/
How is this different from simple assignment.
int b = some_value;
|
by: Steve |
last post by:
Is anyone else experiencing this? I'm seeing about a 1 second lag between
lines as I step through the code. This is happening on 2 machines (I've
only tested two)
I haven't tested it with many other applications, but the one I notice it
the most with is a CAB application. If there are any tricks out there to
fix this... "bug" I would...
| |
by: PeterOut |
last post by:
If I had code like this.
unsigned short usLimit=10
int a, i;
for (i=0; i<(int)usLimit; ++i)
{
a=(int)usLimit;
}
|
by: =?Utf-8?B?SmltIFJvZGdlcnM=?= |
last post by:
My question is simple:
How does one debug ASP Classic with Microsoft Visual Web
Developer Express 2005 ("VWD")?
Looming in the back of anyone's mind when you see a posting
like this on any newsgroup is "didn't this guy read the docs?"
Frankly, I "sort of did" a number of times. I feel the days of
"things that are intuitively obvious" to...
|
by: jim |
last post by:
Maybe I'm missing something, but it doesn't look like Microsoft writes a lot
of apps in .Net (although they certainly push it for others).
What does MS write using pure .Net?
If applications like Symantec's antivirus, NeatReciepts or Franklin Covey's
PlanPlus for Windows is any guide, .Net applications are slow and clunky.
But, maybe the...
|
by: penworthamnaynesh |
last post by:
Does php slow your website down?
This is what i would like to know.The reason is because my site is
writtent 50% in html and 50% in php and is very slow at loading.
And i cant tell wether php is doing it or html o is it another reason
because i only have 20gb bandwidth
My site is called :
ultimate city the game http://www.ultimate-gamez.net
|
by: marktang |
last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main...
|
by: jinu1996 |
last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that...
| |
by: Hystou |
last post by:
Overview:
Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For...
|
by: conductexam |
last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one.
At the time of converting from word file to html my equations which are in the word document file was convert...
|
by: TSSRALBI |
last post by:
Hello
I'm a network technician in training and I need your help.
I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs.
The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols.
I succeeded, with both firewalls in...
|
by: adsilva |
last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
|
by: 6302768590 |
last post by:
Hai team
i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
|
by: muto222 |
last post by:
How can i add a mobile payment intergratation into php mysql website.
| |
by: bsmnconsultancy |
last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating...
| |