Tracking Forums, Newsgroups, Maling Lists
Home Scripts Tutorials Tracker Forums
 
  HOME    TRACKER    Visual Basic




AddPicture Method Word Object Lib


How do I use the Addpicture method of the Word Object Lib to insert pictures into a word document using VB ?




View Complete Forum Thread with Replies

See Related Forum Messages: Follow the Links Below to View Complete Thread
Word Object SendFax Method
I have got the microsoft fax server installed, though when I try and use the sendfax method, no error message is return but nothing happens. Has anyone had any experience of this.

Word Object Document - Sendfax Method
I have got the microsoft fax server installed, though when I try and use the sendfax method of an open word document, no error message is return but nothing happens. Has anyone had any experience of this.



Edited by - RoystonC on 5/14/2003 3:17:14 AM

Quit Method Of MS Word Object Gives Memory Error
Dear Friends ,


I m generating One Report from By Using Visual Basic 6.0 and MS Word Object Library.Creating Object Using CreateObject Method of VB. Word Document is Generated Successfully. But When I m Using Quit Method of It Give A Memory Error (Some Memory Address are not Read) Error Is As Follows


" The instruction at "0x77b2be2e" referenced memory at "0x001c6228". the Memory Could not Be read."


Please Give Me Appropate Solution

Thanks in Advance

Manoj Mevada


Mail ID :
manoj_mevada@tectonas.com

Word Mail Merge Object &"execute&" Method
I am pulling data from various sources and storing them in a temporary table in a MDB file. Then through code I open an invisible instance of Word 2000, open a document with Mail Merge fields in it, set the Mail Merge's datasource with SQL defining records from the MDB file, set the Mail Merge Object to have the "SendToPrinter" property and then invoke the "execute" method. At this point in the program a printer dialog box opens and expects the user to click the "OK" button in order to print the document created through Mail Merge. The problem with this approach is that I am sending thousands of documents to the printer spool so it is impractical to have the user click the printer dialog box "OK" button for each document.

I need a way to have the document automatically sent to the printer spool right after invoking the "execute" method of the Mail Merge Object. It seems like all flow of the program stops once the "execute" method is invoked. I have unsuccessfully tried to use the "Dialogs" collection in Word, the SendKeys statement and the DoEvents function to get the printer dialog box to accept a command from code to simulate that the user hit the "OK" button. I don't care about the fact that the dialog box shows up but I have to find a way to automatically print the document, so I can loop through to repeat the process 4 or 5 thousand times.

I don't know much about sub-classing or hooking, but I believe there could be a solution along those lines. I also thought about but haven't tried to use the "WithEvents" declaration of the Word objects. Any and all help with this problem would be greatly appreciated.

AddPicture
Hello,

I am new to Visual Basic, please excuse my ignorance...

I am trying to place a picture onto a slide in a PowerPoint file using the addPicture method.

'Call newPPTFile.Slides.Item(i).Shapes.AddPicture("C:whatever
ameofslide.g if", msoFalse, msoTrue, 1, 1, 1, 1)'

I keep getting an error message: "Shapes (unknown member): Out of memory "

The Microsoft Site says this is because parameter 2 and parameter 3 are the same - if parameter 2 is true, parameter 3 should be false and vice versa...but that is how I have it and I continue to get the error message. I even tried the code Microsoft had on their site as an example and still received the same error.

Any insight would be greatly appreciated. Thank you.

AddPicture Problem
Hi All,

My VB Code opens a statement in word and my motive is to add a logo to that statement.
The positioning of logo is determined by parameters top, left, width, height which are available to me.
Reading through forums and other documentation I realised that there are 2 ways of adding a picture to a word doc:

1) Using inlineshapes.AddPicture
This accepts a "range" parameter for positioning a picture inline with the text.
2) Using Shapes.AddPicture
This accepts co-ordinates and width height and floats picture on word document.

My Problem is when I use 1st approach i.e. inlineshapes.AddPicture I m unable to control positioning based upon co-ordinates and height width.
And when I use 2nd approach, the picture doesnot appear in my statement (though when I take any word doc and change its extn as my statement type and then try this approach, it works fine but not on original statement.)

I'm sure of lacking some insights on how to use AddPicture.
Any help shall be appreciated.

Thanks and Regards,

Saun

AddPicture Problem
Hi All,

My VB Code opens a statement in word and my motive is to add a logo to that statement.
The positioning of logo is determined by parameters top, left, width, height which are available to me.
Reading through forums and other documentation I realised that there are 2 ways of adding a picture to a word doc:

1) Using inlineshapes.AddPicture
This accepts a "range" parameter for positioning a picture inline with the text.
2) Using Shapes.AddPicture
This accepts co-ordinates and width height and floats picture on word document.

My Problem is when I use 1st approach i.e. inlineshapes.AddPicture I m unable to control positioning based upon co-ordinates and height width.
And when I use 2nd approach, the picture doesnot appear in my statement (though when I take any word doc and change its extn as my statement type and then try this approach, it works fine but not on original statement.)

I'm sure of lacking some insights on how to use AddPicture.
Any help shall be appreciated.

Thanks and Regards,

Saun

AddPicture Locks File
I am automating the insertion of images into the doc I am working on. I use the AddPicture method. However, when I have added the picture, the file that was loaded is locked and cannot be deleted. How do I overcome this problem without having to reload/restart Word or the document?

Thanks

Object Doesnt Support This Object Or Method
i was using the following code:

Dim strBox As String
Dim i As Integer
For i = 0 To (List1.Count - 1)
strBox = strBox & List1.List(i) + vbNewLine
Next i

and I get this error:

object doesnt support this object or method

is there a reference or componet I should have selected to fix this error?

ADO Command Object Returns A &"Method 'Execute' Of Object '_Connection' Failed&" Error
Hi you all,
I have a VB6 app using an Access XP back end.
I Use a function which returns a Read Only, Disconnected ADO Recordset (used to populate lists, combos etc. using minimal resources).
I use it all the time without a hitch.
It started returning a "Method 'Execute' of object '_Connection' failed" error called with a SQL which works just fine when it's used as a query in the Access DB.
Why should the Execute method fail if the SQL works well in Access' Query design window?
Any help will be highly appreciated.
Thanx!
Guy

The function is:
Function GetDisconnectedRS(ByVal sSQL As String) As ADODB.Recordset
Dim adoRS As New ADODB.Recordset
Dim ucmdGetDisconnectedRS As ADODB.Command

Set ucmdGetDisconnectedRS = New ADODB.Command
With ucmdGetDisconnectedRS
.ActiveConnection = oConnect.ConnnectionObject
.CommandType = adCmdText
.CommandText = sSQL

Set adoRS = .Execute()

End With

Set adoRS.ActiveConnection = Nothing
Set GetDisconnectedRS = adoRS

SQL:
SELECT at.ActualTestID, at.PatientID, at.TestID, at.atDate, t.testDescription, p.patFirstName, p.patSurname
FROM (tblActualTests at INNER JOIN tblTests t ON at.TestID = t.TestID) INNER JOIN tblPatients p ON at.PatientID = p.PatientID WHERE at.atDate BETWEEN #02/08/2007# AND #02/08/2007# AND Not atDone
ORDER BY at.atDate DESC, at.TestID, p.patSurname

Just a note: The function works fine few code statements before it fails, with SQLs such as "SELECT DISTINCT patFirstName FROM tblPatients ORDER BY patFirstName".
I've tryed to run "SELECT * FROM tblActualTests" and it does work but hey, what's wrong with a few Joins?
And besides which the function didn't fail me in the past with much more complex SQLs.

Thanx,
Guy

Why Does &"Method 'Open' Of Object 'Workbooks' Failed&" Become &"Method '~'...
I am trapping errors for notification purposes. When I run my program in the IDE the error is:"Method "Method 'Open' of object 'Workbooks' failed"But when I run the compiled executable it excludes information and instead becomes:"Method '~' of object '~' failed"I am not concerned with the reason for the error b/c I already know that. My concern is that the latter does not provide enough information to affectively diagnose the cause of the error.

Why does the error information get dropped in the executable? Is there any way to get it to look like the first message?

Can I Call A Method Of An Object In Runtime By &"object Name&" String?
Private Sub FormShow(FormName as string)

dim f as Form

f = FormName //?????

load f
f.show 1

End Sub

Can I reference to an object by help of its name (string) in runtime?

Method '~' Of Object '~'
Help.. i have gotten this error (Method '~' of Object '~' failed) on several occasions:
when loading a project filewhen adding forms to a projectand now (only happened 3 times) when my compiled .exe is performing an event, but never on the same event..
thanks
-matt

Accessing Word Document 'header/footer' Via Word Object Library
Hi All

As the title suggests really, I can access everything I need on a Word document opened via the Word Library object but I can't find how I access the headers and footers of a docuemnt

Many Thanks
Steve

Packaging Of The Word Automation Program Using Microsoft Word 9.0 Object Library
Hi Gurus!
I made a MS Word Automation program.
In my code, I selected "Microsoft Word 9.0 Object Library" at Project=>References.
Now I want to package that program, so I listed dll, ocx files which is call from my frogram.
But, What file do I have to find for the reference of "Microsoft Word 9.0 Object Library"?
Could anyone let me know?

DonYoung,Jeong

Method '~' Of Object '~' Failed
I've looked trough the whole internet and didnt find any usefull informations.

This error comes up for multiple reason, and for my case it's not because the program is open twice I'm pretty sure it's a problem with ADO object as stated there:

http://support.microsoft.com/default...b;en-us;255986

I noticed this thing happen only on WinXP computers without VB installed...

I tryed to deploy with install shield and with the widzard that come with VB and it dont work... I tryed to change the references from ADO 2.7 to 2.6 but it didnt change...

anyone can help? i've been searching for this for almost a month, now im desesperate.

Method ~ Of Object ~ Failed
Ok, Here is a question for all of you VB Experts:

I am using VB 6.0 SP5. I have a DLL written in VB that generates an Excel spreadsheet using automation. In this case, it is a spreadsheet for a Parts Requisition. When I create a new parts requisition and generate the spreadsheet, there is no problem. When I exit the dialog box and edit the same requsition and try to generate it again, then I get the above error.

This problem only happens when I run the front end application in the VB IDE. It does NOT happen if I run the DLL in a separate VB session to try to debug it. It also does not happen if I compile the front end into an executable and run the executable. It only occurs if the front end is being ran in a single VB session.

Since it does not occur in the Exe, that makes it not so important, but I would still like to know why it is happening and what fix there is for it.
Thanks.

On Using The Create.Object() Method
Hi all,

Since I started programming with VB6, I have always used the Create.Object() method to load a Word or Excel application. For instance:

Code:
Dim xl as Object, wd as Object
Set xl = CreateObject("Excel.Application")
Set wd = CreateObject("Word.Application")
...
I have a question at this point. What is the difference between creating a reference to the Microsoft Word/Excel 11.0 Library and using an Object type to work with office applications?

On one side, no erros whatsoever have ever been raised with the CreateObject() method. On the other side, it does not mean that erros don't exist. Could anyone tell me any tips I should keep in mind and any crucial differences I should be aware of? (I have been programming with VB6 and Office Appl. since 2002).

Method '~'of Object'~' Failed!
Hi there i havent been programming in VB6 for very long and when ive been trying out bits of sample code off the net i getting the error:

Code:
Project failed to build!
Method '~'of Object'~' failed!
This is a very unhelpfull error message as theres not hint as to what might be causing the error or where the problem is located.
Can anyone tell me what its about ?
Can you debug code with this error?
Thanks.

Method '~' Of Object '~' Failed
I get this error on startup of app. I'm sure I don't have something referenced right, but I can't seem to figure it out. Help would be appreciated.

**Module1**
Public con As New ADODB.Connection
Public cmd As New ADODB.Command
Public rs As New ADODB.Recordset

Public Sub StartConnections()
If con.State = 1 Then
con.Close
Else
con.Open "DSN=****;uid=***;pwd=******;"
End If
End Sub


**load of mainform**
Dim crysApp As New CRAXDRT.Application
Dim flag As Boolean
Dim selectedreport As String
Dim myRpt As CRAXDRT.Report
Dim CRXTABLE As CRAXDRT.DatabaseTable

Private Sub Form_Load()
Call StartConnections
Set rs.ActiveConnection = con
rs.Open "Select * from Report_Name", , adOpenForwardOnly

With rs
Do Until .EOF
statecombo.AddItem .Fields(0).Value & " - " & .Fields(1).Value
.MoveNext
Loop
.Close
End With
Set rs = Nothing
End Sub

thanks again
Ed

Method ~ Of Object ~ Failed
Hi all

While starting Visual Basic 6.0 IDE, an error message is thrown. It says

"Method '~' of object '~' failed"

After that when I try to run my program, it gives a compile error:

"Object Library Not Registered"

What could be the cause for that. will I be needed to reinstall the vb 6.0 or is it the problem related to SP5

Thanks

Object & Method Charts
Does anyone know of a website that provides ASP and VB Object charts. These are the charts that list Objects, Methods, & Events and are usually inclueded as a huge posted when you purchase the software.

I am specifically looking for an image, not anything done in just ascii.

Thanks.

Method '~' Of Object '~' Failed
hi guys,

what is this error. Sometimes I get it, sometimes I don't.

Method '~' Of Object '~' Failed
Hi guys

I know this question has been asked millions of times, but I feel I need to ask it again...

I'm having problems using late binding in VB. Now I know that Microsoft has confirmed it to be a bug, (what a laugh... their resolution is to use early binding... WHAT'S THE POINT OF LATE BINDING THEN!?!?!?) but I still need to fix this up.

The thing is... I have about 80 DLL's, and 60 OCX's that I use in my app by use of late binding. Some of the OCX's use some of the DLL's.

These are highly integrated DLL's and OCX's, and I require it to be late bound for upgrade purposes, as compiling all of the code in a single app will result in the EXE being 140MB+... ???

This only happens some times, but when running the app through the VB IDE, I get an error when clicking on something:

Code:
Method '~' of object '~' failed

Automation error -2147417848

When I break this line in the IDE, I can just hit F5 again, and it goes past the line, executing the function successfully. It's definately not a coding error, as it runs past the line on the second attempt. It's as if the DLL is not properly bound... Bare in mind that this does not happen on a single line all the time. This happens all over the place, but randomly... there's not once in a week where it will happen on the same line.

Does anyone have any suggestions or ideas??? I'm begging...

Method ~ Of Object ~ Failed. Can Anyone Help?
Hello all,

I have written an application in VB6 that opens a word document (a template) and performs "find and replace" on data that i pass in. My application is used by external users who log on to our network via Citrix. A few of the users get the error message "Method ~ of Object ~ Failed" (error number -2147023113). The bit of code that this occurs is below:

Do While wrdDoc.Content.Find.Execute( _
FindText:="@" & strReplaceField & "@", _
MatchCase:=False, _
MatchWholeWord:=True, _
ReplaceWith:=strReplacement, _
Replace:=True)
Loop

As fas as i know, its nothing to do with Printer settings or anything, it just seems to be the Execute statement above. Anybody any ideas as to how i can prevent this?

Much appreciated
Nev

Method '~' Of Object '~' Failed
Hiiii
I have this problem.....
I am opening a Excel file through VB. But In some Machines it gives the following error...

Method '~' of Object '~' failed

Can anyone tell me how to resolve this error.....]


Thanx
Sam

Method '~' Of Object '~' Failed
Method '~' of Object '~' Failed

Do you know why Iwould be getting this message on this line? If I run it out of the IDE, it works fine. But if I run the compiled app, I get the above message.


VB Code:
WshShell.Run "chown.exe -R " & UserName & " " & ServerName & shareName & UserName & "*.*", 1, Truertn = Shell("files/chown.exe -R" & strUser & " " & strFolderPath, vbHide)

Method Of Object Failed
First off, here's my code:

Private Sub cmdPrintContract_Click()
' frmContract.Caption = "Print Contract for Cater Number: " & lblCaterNumber.Caption
'frmContract.txtDate.Text = Date

Dim Menu As String

Fill_Menu

rs2.Edit
rs2("Menu") = frmContract.lblMenu.Caption
rs2.Update

Delete_Database

Fill_Database

Dim wrd As Word.Application
If txtTotalKids.Text = "" Then
Set wrd = New Word.Application
wrd.Documents.Open (App.Path + "contract-adults.doc")
Else
Set wrd = New Word.Application
wrd.Documents.Open (App.Path + "contract-children.doc")
End If
wrd.Visible = True
wrd.Activate
End Sub

This works FLAWLESSLY on my computer, but when I install the packaged application on my work computer (also running Windows XP and Office XP) it gives me an error that "Method of ~ Object Failed". It then points to either of the bold lines. I'm guessing its some kind of missing driver or DLL, but the two computers are identical in every way.

I should also point out that when I package the program, it says something about my .EXE being old and I've tried using the one I made and a recompiled one, but no luck. Like I said, the program works FLAWLESSLY in Debug and Packaged/Installed mode on the computer I coded it on. I even installed Visual Basic 6 on the work computer and it won't still won't run in either mode. Can someone help me please!!?!

HWOODKY


I almost forgot. Basically, the problem is in opening Word. It says something about the last time it tried to open this document blah blah blah. Then no matter what I choose, it says the Method Object Failed (or MOF error, as I now call it). The error is in opening Word and I'm stuck!

Method ~ Of Object ~ Failed
Hi all,
I have com add-in which has a button to generate TOC on word documents. But i am getting "Method ~ of object ~ failed" error on MS office 2000. But it is working fine with MS Office XP. I am lost. I tried by installing MDAC_TYP.exe but without any success.

TIA
Shivaraj

Method ~ Of Object ~ Failed
for some reason i'm getting this error when using this code on another pc (win98):


VB Code:
Dim f As Object Set f = CreateObject("Scripting.FileSystemObject")f.CopyFile "c:lah.txt", "LPT1"


it works find on my pc. i've tried setting a reference to the Scripting runtime instead of using CreateObject, but that just says "Object variable or With block variable not set". i've also tried copying my version of scrrun.dll (Scripting Runtime DLL) to the other pc, and registering it, but it still doesn't work. any ideas?

Method '~' Of Object '~' Failed
What a hell is this message ?

Method '~' of object '~' failed

Low memory ?

Method '~' Of Object '~' Failed
hey,

im desparate, i need your help good people
im getting this error only on compiled dll so i cant reproduce it debug or anything, it's not like it's happening everytime... completelty random.

does anybody every had this problem?

Method ~ Of Object ~ Failed?
On a few occassions, the above appeared in a Msgbox when I started VB.

Does anybody know what it means? VB seems to work okay afterwards, so it cannot be a critical issue.

Method '~' Of Object '~' Failed
Has any one seein this error?

Method '~' of object '~' failed.

It comes when i open may VB. It started when I installed office 2000 on my machine...

I don't know the method '~' of the object '~'

any ideas?

Method '~' In Object '~' Not Found.
What is this error? I have this app running on all computers in the company just fine, but only one computer is giving this error. I'm guessing it is something rather simple once you know what it is.

This is happening on an XP (pro?), just did windows critical updates.

Thank you in advance.

Method '~' Of Object '~' Failed
I am getting this message when attempting to preview or save access reports
from visual basic. It does not happen every time or even more regularly on
one machine than another. I am using VB 6 to open/save Access XP reports.
VB 6 is running SP6 and Access is runnning SP3.

Any suggestions would be helpful.



Clint

Method '~' Of Object '~' Failed
Hello Guys,

since a while I'm getting a popup message wheneever I start VB6

It says:

Dataview

Method '~' of object '~' failed.

When I click ok, vb starts up as normal. Everything is working as it should be.

Except in the toolbar, the icoon 'data view window' is grey, and can not be used.

I have already reinstalled VB sp6, but that does not seem to help.

I'm running on Windows XP SP2.

Any Idea's on how to fix this.

Thanks

Err Object And Its Raise Method
Hi folks,

I have an application, where I have to raise Err.Raise method if something goes wrong. Just curious, is there a way that I can raise the error using Err.Raise method and the User, does not have to click the OK button, to make it go away? For instance is there any property, or something that raises the error msgbox and then disappears after some time delay? Just trying to save the user a click

Thanks ia;

I Want To Know If A Method Is Implemented In A COM Object
Hi gurus,

I'm more proficient in C++ than in VB. I've got a VB app using a COM object. I would like my VB app to be backward compatible with older versions of the COM object. In my case the VB app is designed to test the methods on the COM object. The methods available will vary from version to version and I want to be able to hide/show buttons (on the screen) depending on whether or not a particular method is implemented by the COM object. How can I do this in VB?

Thanks

Method '~' Of Object '~' Failed
If I run my application from VB environment and error happens Err.Description has meaningfull information: "Not enough disk space".
But when I run executable from Windows it gives me error number (-2147024784) and description "Method '~' of object '~' failed".

How to overcome this problem?

Thank you in advance.

Object Method Names
Gurus,

Is there an API call that retrieves the names of all the public methods of an object/dll and puts them in some list or array?
Thanks all.

- Pascal

Method '~' Of Object '~' Failed
I have this message when I want to view the report.

Method '~' of object '~' failed.
Runtime error '-2147352567' (80020009)


I am using windows 98 second edition without MSoffice 2000. I am using
VisualBasic 6.0 with SP5 to develop my application. I already added

MSDERUN.DLL (Common FilesDesigners folder)
MSDBRPTR.DLL (System32 Folder)
msstdfmt.dll (System32 Folder)

to my package.

Funny thing is that after I install MSoffice 2000 to this new PC, it works.
The only problem is that I am going to install to other PCs, those PC do not
have license to the MSoffice 2000.

What are the dll is needed????


Please help! A million Thanks!

Method '~' Of Object '~' Failed
I get this error inconsistently when calling a method of a successfully instantiated VB COM object (ActiveX DLL) running under MTS.
Cannot recreate this error consistently.
Please help.......

Method Of Object Failed
I get a "Method of Object Failed Error"
only once ina while.Not on all the com/dcom call s but some calls fails
while VC client tries to access a vb component on MTS.
Same dll when called from a dummy vb client has no problems anyno of times u call it.i have doubt regarding instance release
Can u give me a solution or all possible causes f this error
vc is holding the pointer to component for later calls .
not releasing it and subsequent calls access methods using this global pointer.
But vb code is createobject and set nothing

Using OpenSchema Method In ADO Object
Hi

I would like to know how use OpenSchema method in ADO to list all tables with their column names and datatype of each column and constraints (Primary, Foreign Key etc) in MS Access database. My prime idea is to use them to create tables with contraints in SQL Server on the fly.

After the creation of all the tables chosen from MS Accces in SQL Server, I would like to copy the data from MS Access to SQL Server.

I would be grateful if someone could help me out.


Regards
CR

Convert Html To Word Docuemtn Using The Word Document Object
i ant in vb6 to open an html page
and convert and save it as word *.doc
how can i do this?
and is it possible to open the html file from the internet with a give url so i will be :
open html document from www..../1.html -> save as 1.doc
thnaks in advance
peleg

Picture Object's Render Method
Has anyone seen any documentation on this?

Error: Method '~' Of Object '~' Failed
I am getting the above error while trying to generate word document with
template and bookmarks as input. This error i am getting randomly and not at will in the middle of document generation.

please help me in identifying the problem
Thanks.

here is the code
Code:
Dim I As Integer, j As Integer, k As Integer, l As Integer, m As Integer, docCount As Integer, bookmarksCount As Integer
Dim n As Integer
Dim oWord As Word.Application
Dim oDoc As Document
Dim oSingleDoc As Document
Dim sTemplateUrl As String, sDocStorageURL As String, sDocumentClosed As String, sProtectPassword As String
Dim szServer As String, szUsername As String, szPassword As String, szRemoteFile As String, _
szRefNum As String, szSID As String, szConnect As String, szPortNbr As String
Dim oDocuments As Object, oDocument As Object, oTemplate As Object, oBookmarks As Object, _
oBookmark As Object
Dim sDocument As String, sBookmarkName As String, sBookmarkType As String, _
sBookmarkValue As String, sRowValue As String, sDocUrl As String
Dim sRows() As String, sColumns() As String
Dim rng As Word.Range
Dim frmFields As Word.FormFields
Dim frmField As Word.FormField
Dim rngStart As Integer
Dim rngEnd As Integer
Dim drive As String
Dim frmFieldEnable As Boolean
Dim oBooks As Object
Dim oBook As Object
Dim oContent As Object

On Error GoTo ErrorHandler:
drive = Environ$("SystemDrive")
sProtectPassword = oXML.getElementsByTagName("PasswordProtected").Item(0).Text
Set oDocuments = oXML.getElementsByTagName("Documents").Item(0)
docCount = oDocuments.ChildNodes.Length
sTemplateUrl = drive & oXML.getElementsByTagName("DocTemplateURL").Item(0).Text
sDocStorageURL = oXML.getElementsByTagName("DocStorageURL").Item(0).Text
sDocumentClosed = oXML.getElementsByTagName("DocumentClosed").Item(0).Text
Set oWord = New Word.Application
oWord.Visible = True
Set oDoc = oWord.Documents.Add(sTemplateUrl)
For I = 0 To docCount - 1
Set oDocument = oDocuments.ChildNodes(I)
Set oBooks = CreateObject("MSXML.DOMDocument")
Set oBook = oBooks.documentElement
Set oBook = oBooks.createElement("Books")
oBooks.appendChild oBook
Set oBookmarks = oDocument.getElementsByTagName("Bookmarks").Item(0)
bookmarksCount = oBookmarks.ChildNodes.Length
For n = 0 To bookmarksCount - 1
Set oBookmark = oBookmarks.ChildNodes(n)
Set oContent = oBooks.createElement(oBookmark.getElementsByTagName("Name").Item(0).Text)
oContent.Text = oBookmark.getElementsByTagName("Value").Item(0).Text
oBook.appendChild oContent
Next
Set oTemplate = oDocument.getElementsByTagName("Template").Item(0)
sTemplateUrl = drive & oTemplate.getElementsByTagName("URL").Item(0).Text
Set oSingleDoc = oWord.Documents.Open(FileName:=sTemplateUrl)
oSingleDoc.Activate
Set rng = oSingleDoc.Range
Set frmFields = rng.FormFields
If frmFields.Count > 1 Then
For j = 1 To rng.Bookmarks.Count
If (oBook.SelectNodes("//Books/" & UCase(rng.Bookmarks(j).Name)).Length > 0) Then
sBookmarkName = rng.Bookmarks(j).Name
sBookmarkValue = oBook.getElementsByTagName(UCase(rng.Bookmarks(j).Name)).Item(0).Text
oWord.Selection.GoTo -1, 0, 0, Name:=sBookmarkName
Set frmField = frmFields.Item(sBookmarkName)
frmFieldEnable = frmField.Enabled
frmField.Enabled = True
If frmField.Type = wdFieldFormTextInput Then
frmField.Result = sBookmarkValue
Else
If frmField.Type = wdFieldFormCheckBox Then
If Len(sBookmarkValue) > 0 Then
If StrComp(sBookmarkValue, "Y", vbTextCompare) <= 0 Then
frmField.CheckBox.Value = True
Else
frmField.CheckBox.Value = False
End If
End If
End If
End If
frmField.Enabled = frmFieldEnable
End If
Next
Else
For j = 1 To rng.Bookmarks.Count
If (oBook.SelectNodes("//Books/" & UCase(rng.Bookmarks(j).Name)).Length > 0) Then
sBookmarkValue = oBook.getElementsByTagName(UCase(rng.Bookmarks(j).Name)).Item(0).Text
oWord.Selection.GoTo -1, 0, 0, Name:=rng.Bookmarks(j).Name
If (InStr(sBookmarkValue, "|") > 0) Or (InStr(sBookmarkValue, "?") > 0) Then
sRows = Split(sBookmarkValue, "|")
For k = LBound(sRows) To UBound(sRows)
sColumns = Split(sRows(k), "?")
For l = LBound(sColumns) To UBound(sColumns)
oWord.Selection.TypeText (sColumns(l))
oWord.Selection.MoveRight Unit:=wdCell, Count:=1, Extend:=0
Next
Next
Else
oWord.Selection.TypeText (sBookmarkValue)
End If
End If
Next
End If
sDocUrl = GetPath() & " emp.doc"
oSingleDoc.SaveAs (sDocUrl)
oSingleDoc.Close
Set oBooks = Nothing
oDoc.Activate
oWord.Selection.InsertFile FileName:=sDocUrl
If (I + 1 < docCount) Then
oWord.Selection.EndKey 6, 0
oWord.Selection.InsertBreak 2
oWord.Selection.GoTo rngEnd
End If
Next
oDoc.Protect wdAllowOnlyFormFields, Null, sProtectPassword
szServer = oXML.getElementsByTagName("Servername").Item(0).Text
szUsername = oXML.getElementsByTagName("Username").Item(0).Text
szPassword = oXML.getElementsByTagName("Password").Item(0).Text
szRemoteFile = oXML.getElementsByTagName("RemoteFile").Item(0).Text
szPortNbr = oXML.getElementsByTagName("PortNumber").Item(0).Text
oWord.Run "SetParams", szServer, szUsername, szPassword, szRemoteFile, szPortNbr
If StrComp(sDocumentClosed, "True", vbTextCompare) = 0 Then
oDoc.Close
oWord.Quit
Else
oWord.Visible = True
End If
Set rng = Nothing
Set oSingleDoc = Nothing
Set oDoc = Nothing
Set oWord = Nothing
ErrorHandler:
If Len(Err.Description) > 0 Then
MsgBox "Automation Error: " & Err.Description & " " & Err.Source & " " & Err.Number
oWord.Quit
Set rng = Nothing
Set oDoc = Nothing
Set oSingleDoc = Nothing
Set oWord = Nothing
End If
End Sub

Method 'Rows' Of Object Error
Hello everyone,

I'm starting up a little project in witch i send data from a VB project into a Excel workbook.

The code i use (executed after pressing a button)to do the data transfer works good.....but only for one time.
If i want to do transfer a second time i get a "Method 'Rows' of Object_'Global' failed"

The Code

Code:
Private Sub Command1_Click()
Dim intRow As Integer
Dim XlApp As Excel.Application

On Error GoTo Hell:

Set XlApp = New Excel.Application

XlApp.Visible = False
XlApp.Workbooks.Open FileName:=App.Path & "Log.xls"

'The following line of code gives me trouble
intRow = XlApp.Workbooks("Log").Sheets(1).Cells(Rows.Count, 1).End(xlUp).Row + 1
'I also tried to do it this way
'XlApp.Workbooks("Log").Sheets("1").Range("A1").End(xlDown).Offset(1, 0).Select
'Then some other code stuff...bla,bla...
'but then i got a "Subscript out of range error" !

With XlApp.Workbooks("Log").Sheets(1)
.Cells(intRow, 1).Value = TxtJaar.Text
.Cells(intRow, 2).Value = TxtDag.Text
.Cells(intRow, 3).Value = TxtMaand.Text
.Cells(intRow, 4).Value = CmbFiets.Text
.Cells(intRow, 5).Value = CmbShift.Text
.Cells(intRow, 6).Value = CmbWind.Text
.Cells(intRow, 7).Value = CmbWat.Text
.Cells(intRow, 8).Value = TxtCom.Text
End With

Hell: MsgBox "Dju " & Err.Description

XlApp.Workbooks("Log").Save
XlApp.Workbooks("Log").Close
XlApp.Quit

Set XlApp = Nothing

End Sub

If i close and restart the VB App it again runs fine but again only for one time.

I'm missing ore overlooking something but i don't see it.
I've did a few experiments and tried a few things but i got stuck.

If someone more intelligent than i am would take a look to this code stuff...

Thanks in advance for every intelligent forum member

italkid

Copyright © 2005-08 www.BigResource.com, All rights reserved