473,782 Members | 2,664 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Automation need help

HS1
Hello all

In my window application, I have a button that can open a Word template
(letter). After add some details, I click "Save as" in this Word document.
I can insert a name for this file, then when I close this word file, I want
to print this file name (and its path).
Could you please tell me a method to do that. Below is what I did but it
does seem to work
I created a WithEvents in the module level:
--------
Public WithEvents objWdDoc As Word.Document
------

Then in a button events, I have
Private Sub Button1_Click(B yVal sender As System.Object, ByVal e As
System.EventArg s) Handles Button1.Click

Dim objWdApp As Object

objWdApp = CreateObject("W ord.Application ")

objWdApp.Visibl e = True

objWdDoc = objWdApp.Docume nts.Open(Filena me:="c:\wordTem plate.doc")

-------------------------------------------

Then I have function to handle its Close event.
------

Private Sub objWdApp_Close( )
Debug.Write("ob jWdDoc.FullName ")
set objWdDoc = nothing
End Sub

However, the event seems not work
Could you please help
Many thanks
SH


Nov 21 '05 #1
8 1080
A file with the extension of 'doc' is a Word Document. Word templates have
the file extension 'dot'

What type of information do you want to add?

As soon as you answer me the above question, I will post the cose you want.

Awaiting your reply.

"HS1" wrote:
Hello all

In my window application, I have a button that can open a Word template
(letter). After add some details, I click "Save as" in this Word document.
I can insert a name for this file, then when I close this word file, I want
to print this file name (and its path).
Could you please tell me a method to do that. Below is what I did but it
does seem to work
I created a WithEvents in the module level:
--------
Public WithEvents objWdDoc As Word.Document
------

Then in a button events, I have
Private Sub Button1_Click(B yVal sender As System.Object, ByVal e As
System.EventArg s) Handles Button1.Click

Dim objWdApp As Object

objWdApp = CreateObject("W ord.Application ")

objWdApp.Visibl e = True

objWdDoc = objWdApp.Docume nts.Open(Filena me:="c:\wordTem plate.doc")

-------------------------------------------

Then I have function to handle its Close event.
------

Private Sub objWdApp_Close( )
Debug.Write("ob jWdDoc.FullName ")
set objWdDoc = nothing
End Sub

However, the event seems not work
Could you please help
Many thanks
SH


Nov 21 '05 #2

Thanks for you reply.

Yes, you're right. THe file is wordTemplate.do t.

I'm waiting for your further response. THanks.

SH
*** Sent via Developersdex http://www.developersdex.com ***
Don't just participate in USENET...get rewarded for it!
Nov 21 '05 #3
Hi

Sorry, I forgot to poste the code a few hours ago. After just checking my
e-mail I realised that.

Ok. This is what I have done:

Start a new Windows application

Add reference to the 'Microsoft Word object library' (my library version is
11.0)

Add a button to the form (Button1) & double-click it.

Paste in the following code:

Dim objWord As Word.Applicatio n = New Word.Applicatio n
Dim objDoc As New Word.Document
objWord.Documen ts.Open(Filenam e:="C:\WordTemp late.doc")
objDoc.Range.In sertAfter("Word Question" & ControlChars.Cr Lf)
objDoc.Range.In sertAfter("Solv ed by Crouchie1998")
objWord.Visible = True
objDoc.SaveAs(A pplication.Star tupPath & "\Test.doc" )
Dim strFilename As String = objDoc.FullName
'MessageBox.Sho w(strFilename)
Console.WriteLi ne(strFilename)
objWord.Quit()
objWord = Nothing

---------------------------------

Once again, sorry to keep you waiting

I hope this helps

"john helen" wrote:

Thanks for you reply.

Yes, you're right. THe file is wordTemplate.do t.

I'm waiting for your further response. THanks.

SH
*** Sent via Developersdex http://www.developersdex.com ***
Don't just participate in USENET...get rewarded for it!

Nov 21 '05 #4


*** Sent via Developersdex http://www.developersdex.com ***
Don't just participate in USENET...get rewarded for it!
Nov 21 '05 #5

Thank you for your help

In your code, the file is saved as "Test.doc". Could you please tell me
how to change the default "Test.doc". That means I can input a file name
in "Save As" dialog. when I close this file, I the name of the file is
printed in Console

Thank you
SH1
*** Sent via Developersdex http://www.developersdex.com ***
Don't just participate in USENET...get rewarded for it!
Nov 21 '05 #6
Do you want MS Word to quit each time you've finished entering a filename or
not?

"john helen" wrote:

Thank you for your help

In your code, the file is saved as "Test.doc". Could you please tell me
how to change the default "Test.doc". That means I can input a file name
in "Save As" dialog. when I close this file, I the name of the file is
printed in Console

Thank you
SH1
*** Sent via Developersdex http://www.developersdex.com ***
Don't just participate in USENET...get rewarded for it!

Nov 21 '05 #7
Hi John,

I have re-written the code.

1) Start a new Windows application

2) Add two buttons (Button1 & Button2 respectively)

3) Add a SaveFileDialog (SaveFileDialog 1) control by double-clicking on it
from the toolbox

4) Add a reference to the 'Microsoft Word Object Model'

5) Go to the code view of Form1.

6) At the top, paste in the following line:

Imports Word = Microsoft.Offic e.Interop.Word

7) Paste in the following declarations under the 'form's designer generated
code':

Dim objWord As Word.Applicatio n
Dim objDoc As Word.Document
Dim strTemplate As String = "C:\WordTemplat e.doc"
Dim strFilename As String

8) Switch to form view & double-click 'Button1' & paste in the following
code in the 'click:

If objWord Is Nothing Then
objWord = CreateObject("W ord.Application ")
End If
objDoc = objWord.Documen ts.Open(strTemp late)
Console.WriteLi ne(objDoc.FullN ame)
objWord.Visible = True
objDoc.Range.In sertAfter("Word Automation Text" & ControlChars.Cr Lf)
objDoc.Range.In sertAfter("Crea ted By Crouchie1998")

9) Switch to form view & double-click 'Button2' & paste in the following
code in the 'click:

With SaveFileDialog1
.InitialDirecto ry =
Environment.Get FolderPath(Envi ronment.Special Folder.Desktop)
.DefaultExt = "doc"
.Filter = "Microsoft Word Docs (*.doc)|*.doc|A ll Files (*.*)|*.*"
.FilterIndex = 0
If .ShowDialog = DialogResult.OK Then
strFilename = .FileName
End If
End With
objDoc.SaveAs(s trFilename)
'MessageBox.Sho w(strFilename)
Console.WriteLi ne(strFilename)
CloseWord()

10) Paste in the the following sub:

Private Sub CloseWord()
If Not objWord Is Nothing Then
objWord.Quit()
objWord = Nothing
End If
End Sub

11) Lastly, go to code view, choose 'Form1 Events' from the drop down list.
In the right drop down list choose the 'Form Closing' Enent & paste in this
line of code:

CloseWord()

Now, save the application & run it (F5)

---------------------------------------

I hope this have solved your question
Nov 21 '05 #8


Thank you very very much for your help
I am applying the code
SH

*** Sent via Developersdex http://www.developersdex.com ***
Don't just participate in USENET...get rewarded for it!
Nov 21 '05 #9

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

3
8874
by: Robert | last post by:
---EN--- This message has been crossposted in a french speaking newsgroup, english version is at the end. Thanks a lot for your help... --/EN--- Bonjour, Je développe une application intranet qui "tourne" maintenant depuis plusieurs années auprès de 2500 personnes environ, mais depuis 1 mois,
1
12088
by: mickeydisn | last post by:
Sub: C++ Word automation Extract text hello. I want extact text form a word document using a visual c++ programme. I have see a lot of documentation. and my analysis is that I must use a "word automation". I have foud a lot of exemple to use it but I need your precious help to
15
5848
by: qwweeeit | last post by:
Hi all, Elliot Temple on the 1 June wrote: > How do I make Python press a button on a webpage? I looked at > urllib, but I only see how to open a URL with that. I searched > google but no luck. > For example, google has a button <input type=submit value="Google > Search" name=btnG> how would i make a script to press that button? I have a similar target: web automation, which
25
3744
by: Neil Ginsberg | last post by:
I have a strange situation with my Access 2000 database. I have code in the database which has worked fine for years, and now all of a sudden doesn't work fine on one or two of my client's machines. The code opens MS Word through Automation and then opens a particular Word doc. It's still working fine on most machines; but on one or two of them, the user is getting an Automation Error. The code used is as follows: Dim objWord As...
12
5533
by: Cheval | last post by:
Has anyone had any problems with inter-office automation between MS Word and MS Access in Office 2003? I have recently installed office 2003 in a new folder and have left the older office 2000 and office XP components installed. ie I have word/access/excel 2k/xp/2003 installed. I tried to do a usual access 2k to word 2k automation yet I get the error "Automation Error" "ClassFactory cannot supply requested class" when on late binding try...
1
2407
by: Lee Seung Hoo | last post by:
hi~ :) I need all information of "Automation" or "Automation Object" what is that ? why is it useful ? How can I use that by C# or .Net Framework ?
6
14561
by: Frank X | last post by:
Excel 2002 introduced a capability to add custom worksheet functions to Excel direct from a COM/ActiveX object. I can use C# to develop a COM object which I can use fine from Excel/VBA, however I can't see it using the Excel Tools/Add-Ins - Automation button. Now this appears to be because it is not an *ActiveX* COM object, apparently in order to be an ActiveX object the COM object needs to have a 'CLSID'/Programmable key entry in the...
17
6348
by: Mansi | last post by:
I need to do some research on how to use excel automation from c#. Does anyone know of any good books related to this subject? Thanks. Mansi
6
598
by: a.theil | last post by:
Please help! I need a simple excel automation, just 2 write some files into excel. I do: Dim oXL As Excel.Application Dim oWB As Excel.Workbook Dim oSheet As Excel.Worksheet Dim oRng As Excel.Range
1
1746
by: electrixnow | last post by:
I need some help on automation for office. I found some code I want to use, it looks like this: Variant wordTables = wordActiveDocument.OlePropertyGet( "Tables" ); long table_count = wordTables.OlePropertyGet( "count" ); There is more, it deals with OBJECTS. I have installed Visual C++ and the Platform SDK for VC++. it all was free. I wrote a VC++ program that needs to update bookmarks in a MS Word doc, and then print it. I must do...
0
9639
marktang
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 usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
1
10076
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 most users, this new feature is actually very convenient. If you want to control the update process,...
0
9939
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
8964
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
7486
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
6729
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 into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
1
4040
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
2
3633
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
2870
bsmnconsultancy
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 effective websites that not only look great but also perform exceptionally well. In this comprehensive...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.