怎样把这段VBA代码改写成Delphi代码?急!
Sub Macro4()
'
' Macro4 Macro
' 宏在 2007-4-24 由 我 录制
'
    With ListGalleries(wdNumberGallery).ListTemplates(1).ListLevels(1)
        .NumberFormat = "%1、"
        .TrailingCharacter = wdTrailingTab
        .NumberStyle = wdListNumberStyleArabic
        .NumberPosition = CentimetersToPoints(0)
        .Alignment = wdListLevelAlignLeft
        .TextPosition = CentimetersToPoints(0.74)
        .TabPosition = CentimetersToPoints(0.74)
        .ResetOnHigher = 0
        .StartAt = 1
        With .Font
            .Bold = wdUndefined
            .Italic = wdUndefined
            .StrikeThrough = wdUndefined
            .Subscript = wdUndefined
            .Superscript = wdUndefined
            .Shadow = wdUndefined
            .Outline = wdUndefined
            .Emboss = wdUndefined
            .Engrave = wdUndefined
            .AllCaps = wdUndefined
            .Hidden = wdUndefined
            .Underline = wdUndefined
            .Color = wdUndefined
            .Size = wdUndefined
            .Animation = wdUndefined
            .DoubleStrikeThrough = wdUndefined
            .Name = ""
        End With
        .LinkedStyle = ""
    End With
    ListGalleries(wdNumberGallery).ListTemplates(1).Name = ""
    Selection.Range.ListFormat.ApplyListTemplate ListTemplate:=ListGalleries( _
        wdNumberGallery).ListTemplates(1), ContinuePreviousList:=False, ApplyTo:= _
        wdListApplyToWholeList, DefaultListBehavior:=wdWord10ListBehavior
End Sub

解决方案 »

  1.   

    vba是office的脚本啊,改成delphi的也用不了啊,楼主到底想实现什么
      

  2.   

    我就是想把Delphi控制的Word添加 项目符号(编号)
      

  3.   

    //直接添加这段宏并运行//如果出现“不信任到Visual Basic Project 的程序连接”提示
    //解决办法:开Word->工具->宏->安全性->可靠发行商
    //选中"信任对于Visiual Basic 项目的访问",确定即可。uses VBIDE2000;procedure TForm1.Button1Click(Sender: TObject);
    var
      vFileName: OleVariant;
      vCodeModule: CodeModule;
      vWordDocument: WordDocument;
      vVBComponent: VBComponent;
    begin
      WordApplication1.Connect;
      vFileName := 'c:\temp\temp.doc';
      vWordDocument := WordApplication1.Documents.Open(vFileName, EmptyParam, EmptyParam,
        EmptyParam, EmptyParam, EmptyParam, EmptyParam, EmptyParam, EmptyParam,
        EmptyParam, EmptyParam, EmptyParam);
      WordApplication1.Visible := True;  vVBComponent := vWordDocument.VBProject.VBComponents.Add(
        vbext_ct_StdModule);
      vVBComponent.CodeModule.AddFromString(
    'Sub MyMacro()'#13#10 +
    '    With ListGalleries(wdNumberGallery).ListTemplates(1).ListLevels(1)'#13#10 +
    '        .NumberFormat = "%1、"'#13#10 +
    '        .TrailingCharacter = wdTrailingTab'#13#10 +
    '        .NumberStyle = wdListNumberStyleArabic'#13#10 +
    '        .NumberPosition = CentimetersToPoints(0)'#13#10 +
    '        .Alignment = wdListLevelAlignLeft'#13#10 +
    '        .TextPosition = CentimetersToPoints(0.74)'#13#10 +
    '        .TabPosition = CentimetersToPoints(0.74)'#13#10 +
    '        .ResetOnHigher = 0'#13#10 +
    '        .StartAt = 1'#13#10 +
    '        With .Font'#13#10 +
    '            .Bold = wdUndefined'#13#10 +
    '            .Italic = wdUndefined'#13#10 +
    '            .StrikeThrough = wdUndefined'#13#10 +
    '            .Subscript = wdUndefined'#13#10 +
    '            .Superscript = wdUndefined'#13#10 +
    '            .Shadow = wdUndefined'#13#10 +
    '            .Outline = wdUndefined'#13#10 +
    '            .Emboss = wdUndefined'#13#10 +
    '            .Engrave = wdUndefined'#13#10 +
    '            .AllCaps = wdUndefined'#13#10 +
    '            .Hidden = wdUndefined'#13#10 +
    '            .Underline = wdUndefined'#13#10 +
    '            .Color = wdUndefined'#13#10 +
    '            .Size = wdUndefined'#13#10 +
    '            .Animation = wdUndefined'#13#10 +
    '            .DoubleStrikeThrough = wdUndefined'#13#10 +
    '            .Name = ""'#13#10 +
    '        End With'#13#10 +
    '        .LinkedStyle = ""'#13#10 +
    '    End With'#13#10 +
    '    ListGalleries(wdNumberGallery).ListTemplates(1).Name = ""'#13#10 +
    '    Selection.Range.ListFormat.ApplyListTemplate ListTemplate:=ListGalleries( _'#13#10 +
    '        wdNumberGallery).ListTemplates(1), ContinuePreviousList:=False, ApplyTo:= _'#13#10 +
    '        wdListApplyToWholeList, DefaultListBehavior:=wdWord10ListBehavior'#13#10 +
    'End Sub'#13#10
      );
      WordApplication1.Run('MyMacro');
    end;
      

  4.   

    //翻译一下不是很难,就是费时间procedure TForm1.Button1Click(Sender: TObject);
    const
      wdWord10ListBehavior = $00000002;
    var
      vFileName: OleVariant;
      vWordDocument: WordDocument;
      vListLevel: ListLevel;
      vListTemplate: ListTemplate;
      vIndex: OleVariant;
      vContinuePreviousList: OleVariant;
      vApplyTo: OleVariant;
      vDefaultListBehavior: OleVariant;
    begin
      WordApplication1.Connect;
      vFileName := 'c:\temp\temp.doc';
      vWordDocument := WordApplication1.Documents.Open(vFileName, EmptyParam, EmptyParam,
        EmptyParam, EmptyParam, EmptyParam, EmptyParam, EmptyParam, EmptyParam,
        EmptyParam, EmptyParam, EmptyParam);
      WordApplication1.Visible := True;
      vIndex := 1;
      vListTemplate := WordApplication1.ListGalleries.Item(wdNumberGallery
        ).ListTemplates.Item(vIndex);
      vListLevel := vListTemplate.ListLevels.Item(vIndex);
      vListLevel.NumberFormat := '%1、';
      vListLevel.TrailingCharacter := wdTrailingTab;
      vListLevel.NumberStyle := wdListNumberStyleArabic;
      vListLevel.NumberPosition := WordApplication1.CentimetersToPoints(0);
      vListLevel.Alignment := wdListLevelAlignLeft;
      vListLevel.TextPosition := WordApplication1.CentimetersToPoints(0.74);
      vListLevel.TabPosition := WordApplication1.CentimetersToPoints(0.74);
      vListLevel.ResetOnHigher := 0;
      vListLevel.StartAt := 1;  vListLevel.Font.Bold := wdUndefined;
      vListLevel.Font.Italic := wdUndefined;
      vListLevel.Font.StrikeThrough := wdUndefined;
      vListLevel.Font.Subscript := wdUndefined;
      vListLevel.Font.Superscript := wdUndefined;
      vListLevel.Font.Shadow := wdUndefined;
      vListLevel.Font.Outline := wdUndefined;
      vListLevel.Font.Emboss := wdUndefined;
      vListLevel.Font.Engrave := wdUndefined;
      vListLevel.Font.AllCaps := wdUndefined;
      vListLevel.Font.Hidden := wdUndefined;
      vListLevel.Font.Underline := wdUndefined;
      vListLevel.Font.Color := wdUndefined;
      vListLevel.Font.Size := wdUndefined;
      vListLevel.Font.Animation := wdUndefined;
      vListLevel.Font.DoubleStrikeThrough := wdUndefined;
      vListLevel.Font.Name := '';
      vListTemplate.Name := '';
      vContinuePreviousList := False;
      vApplyTo := wdListApplyToWholeList;
      vDefaultListBehavior := wdWord10ListBehavior;
      WordApplication1.Selection.Range.ListFormat.ApplyListTemplate(vListTemplate,
        vContinuePreviousList, vApplyTo, vDefaultListBehavior);
    end;