Home |
Search |
Today's Posts |
#1
![]()
Posted to microsoft.public.word.vba,microsoft.public.word.docmanagement
|
|||
|
|||
![]()
I have a C# application that creates an instance of Word 2003 and executes a
macro. The macro tries to create a new document using the code below: Application.Documents.add(Template:=strAppPath & "\" & "ErrMsgUserguide.dot", NewTemplate:=False, DocumentType:=0) Every time this line fails. What could be causing this error? If I run the macro from the MS Visual Basic IDE in Word it works fine. Obviously calling the same macro from the C# application has something to do with the problem. Any ideas? |
#2
![]()
Posted to microsoft.public.word.docmanagement
|
|||
|
|||
![]()
Hi,
any ideas? well, if any idea would be welcome, then I'd say: Not that I know much about c#. But if you want to control an application from outside you'll need to declare an object and set it to the application you want to control. Whether this is ExcalVBA or VB or c# doesn't matter. In the end it would like: oWrd.documents.add where oWrd is the Word Application.Object. And there may be more appropriate groups than "docmanagement". -- Greetings from Bavaria, Germany Helmut Weber, MVP WordVBA Win XP, Office 2003 "red.sys" & Chr$(64) & "t-online.de" |
#3
![]()
Posted to microsoft.public.word.vba,microsoft.public.word.docmanagement
|
|||
|
|||
![]()
You have to create a Word object in the C# code and use that instead of
Application. -- http://www.standards.com/; See Howard Kaikow's web site. "techie" wrote in message ... I have a C# application that creates an instance of Word 2003 and executes a macro. The macro tries to create a new document using the code below: Application.Documents.add(Template:=strAppPath & "\" & "ErrMsgUserguide.dot", NewTemplate:=False, DocumentType:=0) Every time this line fails. What could be causing this error? If I run the macro from the MS Visual Basic IDE in Word it works fine. Obviously calling the same macro from the C# application has something to do with the problem. Any ideas? |
#4
![]()
Posted to microsoft.public.word.vba,microsoft.public.word.docmanagement
|
|||
|
|||
![]() "Howard Kaikow" wrote in message ... You have to create a Word object in the C# code and use that instead of Application. I am creating a Word object in my C# code. Its seems that this creates a lock on the Documents collection. The macro is unable to add a new document in Documents. I tried doing the same thing in my C# code and that works. Effectively I've transferred that one line from the macro to my C# and that does the trick. I still don't know what causes the problem. Is it a security issue? The C# application is standalone application rather than a website. |
#5
![]()
Posted to microsoft.public.word.vba,microsoft.public.word.docmanagement
|
|||
|
|||
![]()
I think you're missing the point of Helmut's and Howard's posts
Application.etc. will not work unless "Application" is the name of your object variable which points to the Word object you have created. -- Enjoy, Tony "techie" wrote in message .. . "Howard Kaikow" wrote in message ... You have to create a Word object in the C# code and use that instead of Application. I am creating a Word object in my C# code. Its seems that this creates a lock on the Documents collection. The macro is unable to add a new document in Documents. I tried doing the same thing in my C# code and that works. Effectively I've transferred that one line from the macro to my C# and that does the trick. I still don't know what causes the problem. Is it a security issue? The C# application is standalone application rather than a website. |
#6
![]()
Posted to microsoft.public.word.vba,microsoft.public.word.docmanagement
|
|||
|
|||
![]()
Hi Tony,
I think you're missing the point of Helmut's and Howard's posts Application.etc. will not work unless "Application" is the name of your object variable which points to the Word object you have created. No, I think you an Helmut misunderstood. "Techie" was calling a macro in the Word environment - in a Word VBA project. Application is correct in that case. The problem is that the WORD MACRO apparently can't execute Documents.Add under the given circumstances. Cindy Meister INTER-Solutions, Switzerland http://homepage.swissonline.ch/cindymeister (last update Jun 8 2004) http://www.word.mvps.org This reply is posted in the Newsgroup; please post any follow question or reply in the newsgroup and not by e-mail :-) |
#7
![]()
Posted to microsoft.public.word.vba,microsoft.public.word.docmanagement
|
|||
|
|||
![]()
Ah, I see. Interesting.
What is the failure, techie? Do you get an error code or message? Does it work if you just code Documents.Add (w/o "Application")? And what object pointers do you have set in your C# code? -- Enjoy, Tony "Cindy M -WordMVP-" wrote in message news:VA.0000b848.00a0eb40@speedy... Hi Tony, I think you're missing the point of Helmut's and Howard's posts Application.etc. will not work unless "Application" is the name of your object variable which points to the Word object you have created. No, I think you an Helmut misunderstood. "Techie" was calling a macro in the Word environment - in a Word VBA project. Application is correct in that case. The problem is that the WORD MACRO apparently can't execute Documents.Add under the given circumstances. Cindy Meister INTER-Solutions, Switzerland http://homepage.swissonline.ch/cindymeister (last update Jun 8 2004) http://www.word.mvps.org This reply is posted in the Newsgroup; please post any follow question or reply in the newsgroup and not by e-mail :-) |
#8
![]()
Posted to microsoft.public.word.vba,microsoft.public.word.docmanagement
|
|||
|
|||
![]()
"techie" wrote in message
... I have a C# application that creates an instance of Word 2003 and executes a macro. The macro tries to create a new document using the code below: Application.Documents.add(Template:=strAppPath & "\" & "ErrMsgUserguide.dot", NewTemplate:=False, DocumentType:=0) Every time this line fails. What could be causing this error? If I run the macro from the MS Visual Basic IDE in Word it works fine. Obviously calling the same macro from the C# application has something to do with the problem. Any ideas? To clarify my (mis)understanding: You have a C# program that creates a Word Object, Do you invoke the macro directly fom the C# program? In which case, you have to replace Application with your5 Word object variable. If you are instead, using the Word object you created in C# to open an extant Word document, and the nacro is then run WITHIN Word, then I understand the problem. When you create asn instance of Word in C#, that instance is NOT the same as the Application instance used in the Word code run in Word. so you are dealing with two different document collections. If the latter is the problem, the solution depends on the details of your code, -- http://www.standards.com/; See Howard Kaikow's web site. |
#9
![]()
Posted to microsoft.public.word.vba,microsoft.public.word.docmanagement
|
|||
|
|||
![]()
When you create asn instance of Word in C#, that instance is NOT the same
as the Application instance used in the Word code run in Word. What is it then? Is there something about C# that causes a second instance of Word to be (implicitly) created under some circumstances? -- Enjoy, Tony |
#10
![]()
Posted to microsoft.public.word.vba,microsoft.public.word.docmanagement
|
|||
|
|||
![]()
"Tony Jollans" My Forename at My Surname dot com wrote in message
... When you create asn instance of Word in C#, that instance is NOT the same as the Application instance used in the Word code run in Word. What is it then? Is there something about C# that causes a second instance of Word to be (implicitly) created under some circumstances? It's not a C# issue. Word is a Single Use app. See MSFT KB article 288902, |
#11
![]()
Posted to microsoft.public.word.vba,microsoft.public.word.docmanagement
|
|||
|
|||
![]()
Has the problem in this thread been resolved?
|
#12
![]()
Posted to microsoft.public.word.vba,microsoft.public.word.docmanagement
|
|||
|
|||
![]() "Cindy M -WordMVP-" wrote in message news:VA.0000b848.00a0eb40@speedy... No, I think you an Helmut misunderstood. "Techie" was calling a macro in the Word environment - in a Word VBA project. Application is correct in that case. The problem is that the WORD MACRO apparently can't execute Documents.Add under the given circumstances. Spot on. I trapped the error in the Word macro. A rather strange error (number 5151): Word was unable to read this document. It may be corrupt. Try one or more of the following: *Open and Repair the file. *Open the filewith the Text Recovery converter. If the word file is really corrupt it shouldn't have loaded at all. After loading the document in Word I run a validation macro. This completes fine. Then I call a second macro in another add-in and then this error occurs. Any ideas? |
#13
![]()
Posted to microsoft.public.word.vba,microsoft.public.word.docmanagement
|
|||
|
|||
![]()
Error 5151 probably means the Template can't be found, so what is in
variable strAppPath? -- Enjoy, Tony "techie" wrote in message ... "Cindy M -WordMVP-" wrote in message news:VA.0000b848.00a0eb40@speedy... No, I think you an Helmut misunderstood. "Techie" was calling a macro in the Word environment - in a Word VBA project. Application is correct in that case. The problem is that the WORD MACRO apparently can't execute Documents.Add under the given circumstances. Spot on. I trapped the error in the Word macro. A rather strange error (number 5151): Word was unable to read this document. It may be corrupt. Try one or more of the following: *Open and Repair the file. *Open the filewith the Text Recovery converter. If the word file is really corrupt it shouldn't have loaded at all. After loading the document in Word I run a validation macro. This completes fine. Then I call a second macro in another add-in and then this error occurs. Any ideas? |
Reply |
Thread Tools | |
Display Modes | |
|
|
![]() |
||||
Thread | Forum | |||
Word 2003 mailmerge to HTML mail fails | Mailmerge | |||
OpenDataSource fails | Mailmerge | |||
Normal.dot fails to save anything | Microsoft Word Help | |||
Word 2003 fails to set up Avery labels accurately, why??? | Microsoft Word Help | |||
Mouse wheel fails to scroll help frame in Word 2003. | Microsoft Word Help |