Insert Macros Word 2010 into a Visual Basic 2008 Express Edition

对着背影说爱祢 提交于 2019-12-23 04:23:17

问题


I created a Macro with Microsoft Word 2010:

Sub Macro1()
    Selection.WholeStory
End Sub

At the event Button1_Click I would execute the macro :

Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
    Selection.WholeStory        
End Sub

I remember that Visual Basic 6 allowed to enter Macro object from Microsoft Application. Now with Visual Basic 2008 Express Edition?


回答1:


 Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
    'Funziona  Estrapola in un file HTML
    'Dim settaggio As New XsltSettings
    'Dim xslt As New XslCompiledTransform
    'xslt.Load("Stile.xslt", settaggio, New XmlUrlResolver())
    'xslt.Transform("Fascicolo.xml", "Fascicolo.html")
    'Fine funziona

    ' Create the XslTransform object and load the style sheet. File XSLT
    Dim xslt As New XslCompiledTransform()
    xslt.Load(Label4.Text)
    ' Load the file to transform. File XML
    Dim doc As New Xml.XPath.XPathDocument(Label2.Text)
    ' Create the writer.
    Dim writer As XmlWriter = XmlWriter.Create(DirListBox3.Path & "\" & "Fascicolo.doc", xslt.OutputSettings)
    ' Transform the file and send the output to the console.
    xslt.Transform(doc, writer)
    writer.Close()

    Process.Start(DirListBox3.Path & "\" & "Fascicolo.doc")

    Dim var As New Microsoft.Office.Interop.Word.Application()
    Dim ciao As New Microsoft.Office.Interop.Word.Document
    ciao.Activate()


    var.Documents.Open(FileName:="C:\Users\f.irrera\Desktop\Fascicolo.doc")
    var.Selection.WholeStory()
    var.Selection.Copy()

    var.ChangeFileOpenDirectory("C:\Users\f.irrera\Desktop\")
    var.ActiveDocument.SaveAs2(FileName:="Fascicolo.daf", FileFormat:=2)

    ciao.Close()
    var.Documents.Close()
    var.Application.Quit()

End Sub


来源:https://stackoverflow.com/questions/23658589/insert-macros-word-2010-into-a-visual-basic-2008-express-edition

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!