Reputation: 473
I created this Microsoft Word 2010 Macros:
Sub Crea_DAF()
Selection.WholeStory()
Selection.Copy()
ChangeFileOpenDirectory("C:\Users\f.irrera\Desktop\")
ActiveDocument.SaveAs2(FileName:="Fascicolo.daf", FileFormat:= _
wdFormatText, LockComments:=False, Password:="", AddToRecentFiles:=True, _
WritePassword:="", ReadOnlyRecommended:=False, EmbedTrueTypeFonts:=False, _
SaveNativePictureFormat:=False, SaveFormsData:=False, SaveAsAOCELetter:= _
False, Encoding:=1252, InsertLineBreaks:=False, AllowSubstitutions:=False _
, LineEnding:=wdCRLF, CompatibilityMode:=0)
End Sub
I would execute this macros at Event (using Visual Basic 2008 Express Edition):
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handl
Is it possible?
I am Tryng with:
Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button2.Click
Dim var As New Microsoft.Office.Interop.Word.Application()
var.Selection.WholeStory() <--- Error
var.Selection.Copy()
var.ChangeFileOpenDirectory("C:\Users\f.irrera\Desktop\")
var.ActiveDocument.SaveAs2(FileName:="Fascicolo.daf")
End Sub
This is the error:
Upvotes: 1
Views: 168
Reputation: 473
This run:
Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button2.Click
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", LockComments:=False, Password:="", WritePassword:="", ReadOnlyRecommended:=False, EmbedTrueTypeFonts:=False, SaveNativePictureFormat:=False, SaveFormsData:=False, SaveAsAOCELetter:=False, Encoding:=1252, InsertLineBreaks:=False, AllowSubstitutions:=False, CompatibilityMode:=0)
End Sub
Upvotes: 1
Reputation: 2522
I am not sure you will be able to access all those properties via the object model. You can see here (or search on duckduckgo for word/vb.net programming):
http://www.windowsdevcenter.com/pub/a/windows/2006/04/18/programming-word-from-net.html
Alternatively, add that code into the load on word and then just "shell" open the document to with the macro options:
"C:\Program Files\Microsoft Office\OFFICE11\WinWord.exe" "c:\the.doc" /mDoStuffMacro
OR
via VBS:
Run_Excel_Macro.vbs "C:\Full\Path\To\Your_Excel_Workbook.xls"
Upvotes: 1