Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. Visual Basic
  4. Regarding word application using vb.net

Regarding word application using vb.net

Scheduled Pinned Locked Moved Visual Basic
csharphelplearning
2 Posts 2 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • V Offline
    V Offline
    vijaylumar
    wrote on last edited by
    #1

    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

    T 1 Reply Last reply
    0
    • V vijaylumar

      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

      T Offline
      T Offline
      The Man from U N C L E
      wrote on last edited by
      #2

      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]

      1 Reply Last reply
      0
      Reply
      • Reply as topic
      Log in to reply
      • Oldest to Newest
      • Newest to Oldest
      • Most Votes


      • Login

      • Don't have an account? Register

      • Login or register to search.
      • First post
        Last post
      0
      • Categories
      • Recent
      • Tags
      • Popular
      • World
      • Users
      • Groups