如何调用word宏
Sub Macro1()
'
' Macro1 Macro
' 宏在 2009-4-13 由 USER 录制
'
Selection.MoveUp Unit:=wdLine, Count:=1
Selection.MoveDown Unit:=wdLine, Count:=1
Selection.TypeText Text:="摔跤"
Selection.MoveDown Unit:=wdLine, Count:=1
Selection.TypeText Text:="女子自由式55公斤"
Selection.MoveUp Unit:=wdLine, Count:=2
Selection.MoveDown Unit:=wdLine, Count:=1
Selection.TypeText Text:="秩序单"
Selection.MoveDown Unit:=wdLine, Count:=1
Selection.TypeText Text:="决赛"
Selection.MoveRight Unit:=wdCharacter, Count:=1
Selection.TypeText Text:="2009-04-12 14:20"
Selection.MoveDown Unit:=wdLine, Count:=1
Selection.TypeText Text:="摔跤馆"
Selection.MoveDown Unit:=wdLine, Count:=1
Selection.TypeText Text:="名次 "
ShowVisualBasicEditor = True
End Sub
如何改成c++builder
[解决办法]
OLE专业户来也!!!
#define wdLine 5
#define wdCharacter 1
#define wdExtend 1
void __fastcall TForm1::Button1Click(TObject *Sender)
{
String strDocFile = "C:\\ccrun\\123.doc";
Variant vWordApp;
try
{
vWordApp = Variant::CreateObject("Word.Application");
}
catch(...)
{
MessageBox(Handle, "启动Word出错!",
Application->Title.c_str(), MB_OK
[解决办法]
MB_ICONERROR);
vWordApp = Unassigned;
return;
}
vWordApp.OlePropertyGet("Documents").
OleFunction("Open", strDocFile.c_str());
// 63 63 72 75 6E 2E 63 6F 6D
Variant vSelect = vWordApp.OlePropertyGet("Selection");
vSelect.OleFunction("MoveUp", wdLine, 1);
vSelect.OleFunction("MoveDown", wdLine, 1);
vSelect.OleFunction("TypeText", "摔跤");
vSelect.OleFunction("MoveDown", wdLine, 1);
vSelect.OleFunction("TypeText", "女子自由式55公斤");
vSelect.OleFunction("MoveUp", wdLine, 2);
vSelect.OleFunction("MoveDown", wdLine, 1);
vSelect.OleFunction("TypeText", "秩序单");
vSelect.OleFunction("MoveDown", wdLine, 1);
vSelect.OleFunction("TypeText", "决赛");
vSelect.OleFunction("MoveRight", wdCharacter, 1);
vSelect.OleFunction("TypeText", "2009-04-12 14:20");
vSelect.OleFunction("MoveDown", wdLine, 1);
vSelect.OleFunction("TypeText", "摔跤馆");
vSelect.OleFunction("MoveDown", wdLine, 1);
vSelect.OleFunction("TypeText", "名次 ");
vWordApp.OlePropertyGet("ActiveDocument")
.OleProcedure("SaveAs", strDocFile.c_str());
vWordApp.OleProcedure("Quit");
vWordApp = Unassigned;
ShowMessage("成功完成!");
}