从vb 6开始2007年的单词

时间:2011-06-20 18:41:25

标签: windows vb6 ms-word

我有一个遗留项目,我试图在Windows Server 2003上调试。 1)我无法让应用程序打开word 2007(安装在该机器上)
2)我知道应用程序在写入的其他计算机上打开 - 这些机器正在运行xp或windows终端服务器,
3)申请按标准打开 声明

Private wdApplication           As Word.Application

和代码

  Set wdApplication = GetObject(, "Word.Application")
  If wdApplication Is Nothing Then Set wdApplication = CreateObject("Word.Application")
      If wdApplication Is Nothing Then
         Kill sFileName
  End If
  ' other code
   end if

关于Windows服务器没有设置我需要设置的任何想法 谢谢 我尝试了建议的方法,但没有成功 我查看了我继承的代码库,并找到了一个正确运行单词的应用程序,它是由另一个人设置的(显然) 它使用一个类连接到具有这些功能的单词

Option Explicit
Private bIsNewApp As Boolean
Private sErrorStr As String
Private oWordApp As Object
Private ys As YouthSoft

Public Sub MakeVisible()
  oWordApp.Visible = True
  oWordApp.ActiveDocument.Select
  oWordApp.Selection.GoTo 1, 1
End Sub
Public Sub StartWord()

  'Set oWordApp = GetObject(, "Word.Application")
  If oWordApp Is Nothing Then
    Set oWordApp = CreateObject("Word.Application")
    If oWordApp Is Nothing Then
      sErrorStr = "Microsoft Word could not be located or started. OLE Automation Error"
    Else
      bIsNewApp = True
    End If
  Else
    bIsNewApp = False
  End If

End Sub

这与我应该看到的其他代码有什么区别 我浏览了两个项目的参考和组件,它们在这个功能区域中是相同的

2 个答案:

答案 0 :(得分:2)

添加对“Microsoft Word {VersionNumber}对象库”的引用。

如果有效,请尝试此操作,

Dim objWord As New Word.Application
Dim ActiveWord As New Word.Document

Set objWord = New Word.Application
Set ActiveWord = objWord.Documents.Add(, , wdNewBlankDocument)
objWord.Visible = True
objWord.Activate



With ActiveWord
    .PageSetup.TopMargin = 1 * 72
    .PageSetup.BottomMargin = 1 * 72
    .PageSetup.LeftMargin = 1.25 * 72
    .PageSetup.RightMargin = 1.25 * 72
    .ActiveWindow.Application.Selection.TypeText "Test"
End With

Set objWord = Nothing
Set ActiveWord = Nothing

答案 1 :(得分:2)

问题可能是Word应用程序实例DID加载但是被隐藏。

尝试以下操作,它始终与我合作:

Dim WD As New Word.Application
WD.Visible = True
'from here Word should open and have no active documents opened
'here is how to open documents
WD.Documents.Open "C:\FileName.doc"