VB automation of Word 2007

C

cj2

I open a word template in VB and add values to the bookmarks then save
the document as as pdf. When I then go to close the document it pops up
a save as dialog box. It's already saved the document in pdf and that
is all I want done with it. How can I tell it to close the file without
prompting me for anything?

For Each row As DataRow In myDt.Rows
Dim objWord As Application
Dim objDoc As Document
objWord = CreateObject("Word.Application")
objDoc = objWord.Documents.Add("c:\Collections.dotx")
objDoc.Bookmarks.Item("CUSTNO").Range.Text = row.Item("custno")
objDoc.Bookmarks.Item("DATE").Range.Text = DateString()
objDoc.SaveAs("c:\test\" & row.Item("custno") & "Collection",
WdSaveFormat.wdFormatPDF)
objDoc.Close()
Next
 
C

Cor Ligthert[MVP]

CJ,

Not to send you away or anything, it is not impossible that there is
somebody watching this newsgroup who knows the answer on your question.
Because you have stated your subject in a way that it is not covering your
problem it is however already lower (It is about a very special isolated
problem of VB automation of Word).

In your case I would ask this question in an office programming newsgroup
because if it is done with VB, VBA, C#, Java, C++ does not change your
problem that there is in the office class something that automaticly creates
a popup.

Cor
 
J

Jialiang Ge [MSFT]

Hello CJ,

Saving a Word document as PDF (SaveAs WdSaveFormat.wdFormatPDF) behaves
differently from saving the document as Word format, e.g. docx/doc. Let's
first look at the resolution of the issue, then I will explain "WHY".

*** RESOLUTION ***
Change the code line
objDoc.Close()
to
objDoc.Close(false)

In other words, we pass false to the param "SaveChange" of the Close
method, to discard the change of the Word document.

*** CAUSE ***
In fact, this code line only *exports* the current Word document to a PDF
file:
objDoc.SaveAs("c:\test\" & row.Item("custno") & "Collection",
WdSaveFormat.wdFormatPDF)

It does not save the current Word document. Therefore, we get a SaveAs
dialog when we close the document with objDoc.Close()

Please try the solution and let me know whether it's helpful to you or not.

P.S. As Cor suggested, a more proper newsgroup for this Office automation
issue is
microsoft.public.office.developer.automation
For the list of the managed newsgroups, please refer to the page
http://msdn.microsoft.com/en-us/subscriptions/aa974230.aspx

Regards,
Jialiang Ge ([email protected], remove 'online.')
Microsoft Online Community Support

Delighting our customers is our #1 priority. We welcome your comments and
suggestions about how we can improve the support we provide to you. Please
feel free to let my manager know what you think of the level of service
provided. You can send feedback directly to my manager at:
(e-mail address removed).

==================================================
Get notification to my posts through email? Please refer to
http://msdn.microsoft.com/subscriptions/managednewsgroups/default.aspx#notif
ications.

Note: The MSDN Managed Newsgroup support offering is for non-urgent issues
where an initial response from the community or a Microsoft Support
Engineer within 1 business day is acceptable. Please note that each follow
up response may take approximately 2 business days as the support
professional working with you may need further investigation to reach the
most efficient resolution. The offering is not appropriate for situations
that require urgent, real-time or phone-based interactions or complex
project analysis and dump analysis issues. Issues of this nature are best
handled working with a dedicated Microsoft Support Engineer by contacting
Microsoft Customer Support Services (CSS) at
http://msdn.microsoft.com/subscriptions/support/default.aspx.
==================================================
This posting is provided "AS IS" with no warranties, and confers no rights.
 
C

cj2

Thanks, that's what I needed. I understand what you mean by exporting
to pdf. Word then feels like it isn't saved and wants to save it upon
exiting. I could not figure out the options for close() but they make
sense now.

Also thanks to you and Cor for pointing out
Microsoft.public.office.developer.automation and the list of groups.
Actually this makes me wonder if there is a better way to access these
groups? Right now I'm using Mozilla Thunderbird and subscribe to
microsoft.public.dotnet.languages.vb for example. I like that I can
mark post Ignore and I don't see them leaving only a list of those
threads I am interested in. I leave them in Thunderbird so I can refer
back to them later if I forget. I don't like that after about 3 months
the threads only display that the article has expired. My only
workaround is going to Google NewsGroups and searching for the group
then for the subject of thread. They still have it.
 
C

Cor Ligthert[MVP]

cj,

Can you try this link
news://msnews.microsoft.com/microsoft.public.office.developer.automation

And please tell us if it did work

Cor
 
C

cj2

Well, that will cause Thunderbird to ask if I want to subscribe. I was
just wondering if there was a better way other than Thunderbird. How do
other folks access these forums?
 
C

Cor Ligthert[MVP]

Mostly Outlook Express (in Vista Windows mail)

As Thunderbird had not been your default newsreader that would have been
opened, therefore I asked you to reply.

Cor

cj2 said:
Well, that will cause Thunderbird to ask if I want to subscribe. I was
just wondering if there was a better way other than Thunderbird. How do
other folks access these forums?
cj,

Can you try this link
news://msnews.microsoft.com/microsoft.public.office.developer.automation

And please tell us if it did work

Cor


cj2 said:
Thanks, that's what I needed. I understand what you mean by exporting
to pdf. Word then feels like it isn't saved and wants to save it upon
exiting. I could not figure out the options for close() but they make
sense now.

Also thanks to you and Cor for pointing out
Microsoft.public.office.developer.automation and the list of groups.
Actually this makes me wonder if there is a better way to access these
groups? Right now I'm using Mozilla Thunderbird and subscribe to
microsoft.public.dotnet.languages.vb for example. I like that I can
mark post Ignore and I don't see them leaving only a list of those
threads I am interested in. I leave them in Thunderbird so I can refer
back to them later if I forget. I don't like that after about 3 months
the threads only display that the article has expired. My only
workaround is going to Google NewsGroups and searching for the group
then for the subject of thread. They still have it.



Jialiang Ge [MSFT] wrote:
Hello CJ,

Saving a Word document as PDF (SaveAs WdSaveFormat.wdFormatPDF) behaves
differently from saving the document as Word format, e.g. docx/doc.
Let's first look at the resolution of the issue, then I will explain
"WHY".

*** RESOLUTION ***
Change the code line objDoc.Close()
to objDoc.Close(false)

In other words, we pass false to the param "SaveChange" of the Close
method, to discard the change of the Word document.

*** CAUSE ***
In fact, this code line only *exports* the current Word document to a
PDF file:
objDoc.SaveAs("c:\test\" & row.Item("custno") & "Collection",
WdSaveFormat.wdFormatPDF)

It does not save the current Word document. Therefore, we get a SaveAs
dialog when we close the document with objDoc.Close()

Please try the solution and let me know whether it's helpful to you or
not.

P.S. As Cor suggested, a more proper newsgroup for this Office
automation issue is microsoft.public.office.developer.automation
For the list of the managed newsgroups, please refer to the page
http://msdn.microsoft.com/en-us/subscriptions/aa974230.aspx

Regards,
Jialiang Ge ([email protected], remove 'online.')
Microsoft Online Community Support

Delighting our customers is our #1 priority. We welcome your comments
and suggestions about how we can improve the support we provide to you.
Please feel free to let my manager know what you think of the level of
service provided. You can send feedback directly to my manager at:
(e-mail address removed).

==================================================
Get notification to my posts through email? Please refer to
http://msdn.microsoft.com/subscriptions/managednewsgroups/default.aspx#notif
ications.

Note: The MSDN Managed Newsgroup support offering is for non-urgent
issues where an initial response from the community or a Microsoft
Support Engineer within 1 business day is acceptable. Please note that
each follow up response may take approximately 2 business days as the
support professional working with you may need further investigation to
reach the most efficient resolution. The offering is not appropriate
for situations that require urgent, real-time or phone-based
interactions or complex project analysis and dump analysis issues.
Issues of this nature are best handled working with a dedicated
Microsoft Support Engineer by contacting Microsoft Customer Support
Services (CSS) at
http://msdn.microsoft.com/subscriptions/support/default.aspx.
==================================================
This posting is provided "AS IS" with no warranties, and confers no
rights.
 
C

cj2

I'm not sure I understand. Thunderbird is my default reader. I don't
use Outlook Express. However, I am moving (being forced to move) from
Thunderbird to Outlook for email in the near future and wonder if I
should look for another news group reader.

Mostly Outlook Express (in Vista Windows mail)

As Thunderbird had not been your default newsreader that would have been
opened, therefore I asked you to reply.

Cor

cj2 said:
Well, that will cause Thunderbird to ask if I want to subscribe. I
was just wondering if there was a better way other than Thunderbird.
How do other folks access these forums?
cj,

Can you try this link
news://msnews.microsoft.com/microsoft.public.office.developer.automation

And please tell us if it did work

Cor


"cj2" <[email protected]> schreef in bericht
Thanks, that's what I needed. I understand what you mean by
exporting to pdf. Word then feels like it isn't saved and wants to
save it upon exiting. I could not figure out the options for
close() but they make sense now.

Also thanks to you and Cor for pointing out
Microsoft.public.office.developer.automation and the list of groups.
Actually this makes me wonder if there is a better way to access
these groups? Right now I'm using Mozilla Thunderbird and subscribe
to microsoft.public.dotnet.languages.vb for example. I like that I
can mark post Ignore and I don't see them leaving only a list of
those threads I am interested in. I leave them in Thunderbird so I
can refer back to them later if I forget. I don't like that after
about 3 months the threads only display that the article has
expired. My only workaround is going to Google NewsGroups and
searching for the group then for the subject of thread. They still
have it.



Jialiang Ge [MSFT] wrote:
Hello CJ,

Saving a Word document as PDF (SaveAs WdSaveFormat.wdFormatPDF)
behaves differently from saving the document as Word format, e.g.
docx/doc. Let's first look at the resolution of the issue, then I
will explain "WHY".

*** RESOLUTION ***
Change the code line objDoc.Close()
to objDoc.Close(false)

In other words, we pass false to the param "SaveChange" of the
Close method, to discard the change of the Word document.

*** CAUSE ***
In fact, this code line only *exports* the current Word document to
a PDF file:
objDoc.SaveAs("c:\test\" & row.Item("custno") & "Collection",
WdSaveFormat.wdFormatPDF)

It does not save the current Word document. Therefore, we get a
SaveAs dialog when we close the document with objDoc.Close()

Please try the solution and let me know whether it's helpful to you
or not.

P.S. As Cor suggested, a more proper newsgroup for this Office
automation issue is microsoft.public.office.developer.automation
For the list of the managed newsgroups, please refer to the page
http://msdn.microsoft.com/en-us/subscriptions/aa974230.aspx

Regards,
Jialiang Ge ([email protected], remove 'online.')
Microsoft Online Community Support

Delighting our customers is our #1 priority. We welcome your
comments and suggestions about how we can improve the support we
provide to you. Please feel free to let my manager know what you
think of the level of service provided. You can send feedback
directly to my manager at: (e-mail address removed).

==================================================
Get notification to my posts through email? Please refer to
http://msdn.microsoft.com/subscriptions/managednewsgroups/default.aspx#notif

ications.

Note: The MSDN Managed Newsgroup support offering is for non-urgent
issues where an initial response from the community or a Microsoft
Support Engineer within 1 business day is acceptable. Please note
that each follow up response may take approximately 2 business days
as the support professional working with you may need further
investigation to reach the most efficient resolution. The offering
is not appropriate for situations that require urgent, real-time or
phone-based interactions or complex project analysis and dump
analysis issues. Issues of this nature are best handled working
with a dedicated Microsoft Support Engineer by contacting Microsoft
Customer Support Services (CSS) at
http://msdn.microsoft.com/subscriptions/support/default.aspx.
==================================================
This posting is provided "AS IS" with no warranties, and confers no
rights.
 
P

Phill W.

cj2 said:
I'm not sure I understand. Thunderbird is my default reader. I don't
use Outlook Express. However, I am moving (being forced to move) from
Thunderbird to Outlook for email in the near future and wonder if I
should look for another news group reader.

? [Outlook] = [Outlook Express]
False

? [Outlook Express] = functionOf( [Outlook] )
False

They are completely different products but with similar names - Oooh;
where have we heard that one before? :)

I happily use Outlook for my email and Thunderbird as my news client -
so long as you turn off the "default client" auto-detection, you
shouldn't have any major problems running both.

HTH,
Phill W.
 
C

cj2

? [Outlook] = [Outlook Express]
False

? [Outlook Express] = functionOf( [Outlook] )
False
I know that. (No offense intended) Again, I don't use Outlook Express.
However, I am moving (being forced to move) from Thunderbird to
Outlook for email in the near future and wonder if I should look for
another news group reader.

Further, I don't think it makes sense to use Outlook Express for the
news group reader and Outlook for mail. Of course I could be wrong on
that--it would just seem to me that Outlook should do everything Outlook
Express does.

Anyway it would seem most people use Outlook Express. Question answered.

cj2 said:
I'm not sure I understand. Thunderbird is my default reader. I don't
use Outlook Express. However, I am moving (being forced to move) from
Thunderbird to Outlook for email in the near future and wonder if I
should look for another news group reader.

? [Outlook] = [Outlook Express]
False

? [Outlook Express] = functionOf( [Outlook] )
False

They are completely different products but with similar names - Oooh;
where have we heard that one before? :)

I happily use Outlook for my email and Thunderbird as my news client -
so long as you turn off the "default client" auto-detection, you
shouldn't have any major problems running both.

HTH,
Phill W.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top