Enlace tardío para evitar el error "Tipo definido por el usuario no definido"
Frecuentes
Visto 1,467 veces
0
En Word 2010 macro VBA, configuré
Set objXML = New MSXML2.DOMDocument30
para obtener el archivo Word.officeUI tipo xml.
Pero cuando llamo al sub que maneja el archivo Word.officeUI
user defined type not defined
aumentó el error.
No quiero agregar ningún .dll necesario u otra fuente de HERRAMIENTAS> REFERENCIAS. Necesito agregar algo en tiempo de ejecución (primera apertura de Word). Aquí está mi código real en uso a continuación,
' 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
1 Respuestas
3
Aquí se explica cómo hacerlo en tiempo de ejecución:
Dim objXML As Object
Set objXML = CreateObject("Msxml2.DOMDocument.3.0")
Ahora no necesita establecer una referencia explícita a MSXML.
Respondido el 02 de diciembre de 13 a las 08:12
No es la respuesta que estás buscando? Examinar otras preguntas etiquetadas vba ms-word domdocument msxml or haz tu propia pregunta.
Lo siento por el título mal significado. No hay referencias de límite inicial o límite previo. - caglaror