Regarding word application using vb.net
-
hi all in my project i have a task with Ms word application i have to open the already existing word document and i have to pass the values to the bookmarks in that document i written the following code Dim wordapp As New Word.Application wordapp = Nothing wordapp = CreateObject("word.application") Dim olddoc As Word.Document olddoc = wordapp.Documents.Open(AppPath + "Designs\Gantry2.doc") 'book marks For i As Integer = 0 To 48 With wordapp.ActiveDocument .Bookmarks.Item("b" + i.ToString()).Range.Text = DG_GanDict.Item("b" + i.ToString()) End With Next wordapp.ActiveDocument.SaveAs("test.doc") wordapp.Visible = True the above code works in Ms office 2003 but the same code does not works or executes in ms office 2007 even though i added the refernce when i run it in ms office 2007 i get Runtime.InteropServices.COMException This file could not be found. (C:\//Program%20Files/VCS/...) and ErrorCode = -2146823114 that to it happens in c:\ drive only when i copy and paste the application in other drive like D:\ it executes properly can any one have a idea about this problem and is there any common code which runs in ms office 2003 and 2007 versions thanks in advance vijay kumar d
-
hi all in my project i have a task with Ms word application i have to open the already existing word document and i have to pass the values to the bookmarks in that document i written the following code Dim wordapp As New Word.Application wordapp = Nothing wordapp = CreateObject("word.application") Dim olddoc As Word.Document olddoc = wordapp.Documents.Open(AppPath + "Designs\Gantry2.doc") 'book marks For i As Integer = 0 To 48 With wordapp.ActiveDocument .Bookmarks.Item("b" + i.ToString()).Range.Text = DG_GanDict.Item("b" + i.ToString()) End With Next wordapp.ActiveDocument.SaveAs("test.doc") wordapp.Visible = True the above code works in Ms office 2003 but the same code does not works or executes in ms office 2007 even though i added the refernce when i run it in ms office 2007 i get Runtime.InteropServices.COMException This file could not be found. (C:\//Program%20Files/VCS/...) and ErrorCode = -2146823114 that to it happens in c:\ drive only when i copy and paste the application in other drive like D:\ it executes properly can any one have a idea about this problem and is there any common code which runs in ms office 2003 and 2007 versions thanks in advance vijay kumar d
One problem may be the use of CreateObject.
vijaylumar wrote:
Dim wordapp As New Word.Application wordapp = Nothing wordapp = CreateObject("word.application")
You got an instance of the Word Application object already so why ditch it and attemt to recreate it in the old VB6 style? As for 2003/2007 execution, I don't see any 2007 specific code here. Target the 2003 interop assemblies, make sure you include them in your deployment, and it will work fine against 2007 as well. In fact I just installed Office 2010 and the 2003 Interop Assemblies still work against 2010!
If you have knowledge, let others light their candles at it. Margaret Fuller (1810 - 1850) [My Articles] [My Website]