延迟绑定以避免“未定义用户定义类型”。错误 [英] Late binding to avoid "User defined type not defined" error

查看:92
本文介绍了延迟绑定以避免“未定义用户定义类型”。错误的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在Word 2010宏VBA中,我设置

In Word 2010 macro VBA, i set

Set objXML = New MSXML2.DOMDocument30

来获取xml类型的Word.officeUI文件。

to get xml type Word.officeUI file.

但是当我调用sub处理Word.officeUI文件

But when i call the sub that handling Word.officeUI file

user defined type not defined

错误增加了。

我不想添加任何必要的.dll或TOOLS中的其他来源>参考
我需要在运行时添加任何内容(第一次打开Word)。
这是我在下面使用的实际代码,

I don't want to add any necessary .dll or another source from TOOLS > REFERENCES I need to add any thing in run time (first opening of Word). Here is my actual code in use at below,

' bu özel sub sadece onLoad event'ına karşılık gelen ve belge ilk defa yüklendiğinde çalışan özel bir sub
Private Sub Document_Open()
Application.ActiveDocument.VBProject.References.AddFromFile ("C:\Windows\System32\msxml3.dll")
Call officeUI_duzelt
End Sub

Function yeniDosyaAdiVer()
yeniDosyaAdiKelimeleri = Split(ActiveDocument.FullName, ".")
yeniDosyaAdiKelimeleriSayisi = UBound(yeniDosyaAdiKelimeleri)
    For xcv = 0 To (yeniDosyaAdiKelimeleriSayisi - 1)
        sonDosyaAdi = sonDosyaAdi & yeniDosyaAdiKelimeleri(xcv) & "."
        yeniDosyaAdiVer = sonDosyaAdi
    Next
End Function


Sub TITCK2pdf()
    With ActiveDocument
    sondurum = Replace(yeniDosyaAdiVer(), (.Path & "\"), "")
    'MsgBox (sondurum)
    sonPDFAdi = .Path & "\titck-imza-" & sondurum & "pdf"
    'MsgBox (.FullName & Chr(13) & sonPDFAdi)

      .ExportAsFixedFormat OutputFileName:=sonPDFAdi, _
      ExportFormat:=wdExportFormatPDF, OpenAfterExport:=False, _
      OptimizeFor:=wdExportOptimizeForPrint, Range:=wdExportAllDocument, _
      Item:=wdExportDocumentContent, IncludeDocProps:=True, KeepIRM:=True, _
      CreateBookmarks:=wdExportCreateNoBookmarks, DocStructureTags:=True, _
      BitmapMissingFonts:=True, UseISO19005_1:=False
    End With
End Sub

Sub TITCK_ic2pdf()
    With ActiveDocument
    sondurum = Replace(yeniDosyaAdiVer(), (.Path & "\"), "")
    'MsgBox (sondurum)
    sonPDFAdi = .Path & "\titck-imza-ic-" & sondurum & "pdf"
    'MsgBox (.FullName & Chr(13) & sonPDFAdi)

      .ExportAsFixedFormat OutputFileName:=sonPDFAdi, _
      ExportFormat:=wdExportFormatPDF, OpenAfterExport:=False, _
      OptimizeFor:=wdExportOptimizeForPrint, Range:=wdExportAllDocument, _
      Item:=wdExportDocumentContent, IncludeDocProps:=True, KeepIRM:=True, _
      CreateBookmarks:=wdExportCreateNoBookmarks, DocStructureTags:=True, _
      BitmapMissingFonts:=True, UseISO19005_1:=False
    End With
End Sub

Sub officeUI_duzelt()
' // OfficeUI dosyasının yolu alınıyor
OfficeUI_yolu = "C:\Users\" & Environ$("Username") & "\AppData\Local\Microsoft\Office\Word.officeUI"

' // OfficeUI dosyası (xml formatında) ele alınıyor
Set objXML = New MSXML2.DOMDocument30
objXML.Load (OfficeUI_yolu)

'// OfficeUI içindeki node bilgileri ele alınıyor
Set dugmelerinAnaci = objXML.getElementsByTagName("mso:sharedControls")(0)


'// Daha önce değişiklik yapılmış mı  kontrol amaçlı girdi bakılıyor
Set modifikasyon = objXML.getElementsByTagName("modifikasyon")

'// Modifikasyon yapıldıysa sub'dan çıkılıyor
'MsgBox (modifikasyon.Length)
If modifikasyon.Length > 0 Then
Exit Sub
End If
'/////////////////////////////////////// SUB çıkış şartı var üstte

' // Her durumda modifikasyon yapılacak (modifikasyon nodu eklenecek (mso:sharedControls ana nodunun altına ekleniyor)
Set mdf = objXML.createElement("modifikasyon")
dugmelerinAnaci.appendChild mdf




'// mso:button node'larına ait xml içerikleri gösteriliyor
'Set yeniDegerler = objXML.getElementsByTagName("mso:button")
'For yD = 0 To (yeniDegerler.Length - 1)
'MsgBox (yeniDegerler(yD).XML)
'Next



' Element ekleniyor ve o elemente attribute'lar ekleniyor
Set yNesne = elementYaratVeEkle("mso:button", dugmelerinAnaci, objXML)
    yAttribute = attributeYaratVeEkle("idQ", "x1:TITCK_ic2pdf_1", yNesne, objXML)
    yAttribute = attributeYaratVeEkle("visible", "true", yNesne, objXML)
    yAttribute = attributeYaratVeEkle("label", "İç yazışma PDF yapıcısı", yNesne, objXML)
    yAttribute = attributeYaratVeEkle("imageMso", "AppointmentColor3", yNesne, objXML)
    yAttribute = attributeYaratVeEkle("onAction", "TITCK_ic2pdf", yNesne, objXML)

Set yNesne = elementYaratVeEkle("mso:button", dugmelerinAnaci, objXML)
    yAttribute = attributeYaratVeEkle("idQ", "x1:TITCK2pdf_1", yNesne, objXML)
    yAttribute = attributeYaratVeEkle("visible", "true", yNesne, objXML)
    yAttribute = attributeYaratVeEkle("label", "Dış yazışma PDF yapıcısı", yNesne, objXML)
    yAttribute = attributeYaratVeEkle("imageMso", "AppointmentColor1", yNesne, objXML)
    yAttribute = attributeYaratVeEkle("onAction", "TITCKpdf", yNesne, objXML)



've kayıt
objXML.Save (OfficeUI_yolu)
End Sub
Function elementYaratVeEkle(elementAdi, AnacElementNesnesi, hazirXMLNesnesi)
Set objYeniNesne = hazirXMLNesnesi.createElement(elementAdi)
AnacElementNesnesi.appendChild objYeniNesne
Set elementYaratVeEkle = objYeniNesne
End Function
Function attributeYaratVeEkle(attributeAdi, attributeDegeri, AnacElementNesnesi, hazirXMLNesnesi)
Set objXMLattr = hazirXMLNesnesi.createAttribute(attributeAdi)
objXMLattr.NodeValue = attributeDegeri
AnacElementNesnesi.setAttributeNode objXMLattr
End Function


推荐答案

使其晚绑定:

Dim objXML As Object
Set objXML = CreateObject("Msxml2.DOMDocument.3.0")

现在,您无需为MSXML设置显式引用。

Now you don't need to set an explicit reference to MSXML.

这篇关于延迟绑定以避免“未定义用户定义类型”。错误的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆