以文本方式查看主题

-  Foxtable(狐表)  (http://foxtable.com/bbs/index.asp)
--  专家坐堂  (http://foxtable.com/bbs/list.asp?boardid=2)
----  [求助]VBA问题  (http://foxtable.com/bbs/dispbbs.asp?boardid=2&id=65590)

--  作者:pcxjxjhkw
--  发布时间:2015/3/18 17:25:00
--  [求助]VBA问题
如何用VBA新建一个word文档并保存到指定路径下。
--  作者:Bin
--  发布时间:2015/3/18 17:27:00
--  
复制狐表目录的 blank.doc 文件过来即可
--  作者:pcxjxjhkw
--  发布时间:2015/3/18 17:30:00
--  
Bin,是要用代码呀


--  作者:有点甜
--  发布时间:2015/3/18 17:31:00
--  
 新增一个word

 

Dim app As New MSWord.Application
\'新建文档
Dim missing = System.Reflection.Missing.Value
Dim nDoc = App.Documents.Add(missing, missing, missing, missing)
nDoc.SaveAs("d:\\test.doc")
app.quit
msgbox("新建word成功")

 

 删除一个文件

http://www.foxtable.com/help/topics/0338.htm


--  作者:pcxjxjhkw
--  发布时间:2015/3/19 15:51:00
--  
下面代码报错,CentimetersToPoints不声明。
如何修改?谢谢

App.Selection.ParagraphFormat.LineSpacingRule = Microsoft.Office.Interop.Word.WdLineSpacing.wdLineSpaceSingle    \'\'单倍行距
    With app.Selection.ParagraphFormat    \'\'首行不缩进
        .FirstLineIndent = CentimetersToPoints(0)
        .CharacterUnitFirstLineIndent = 0
    End With

--  作者:有点甜
--  发布时间:2015/3/19 15:53:00
--  
app.CentimetersToPoints(0)
--  作者:pcxjxjhkw
--  发布时间:2015/3/19 15:54:00
--  
谢谢
--  作者:pcxjxjhkw
--  发布时间:2015/3/19 16:01:00
--  
甜老师,以下代码未能实现:取消首行缩进。麻烦您帮我优化一下代码 ,谢谢

Dim app As New MSWord.Application

try
    
    \'新建文档
    Dim missing = System.Reflection.Missing.Value
    Dim nDoc = App.Documents.Add(missing, missing, missing, missing)
    
    
    App.Selection.ParagraphFormat.LineSpacingRule = Microsoft.Office.Interop.Word.WdLineSpacing.wdLineSpaceSingle    \'\'单倍行距
    With app.Selection.ParagraphFormat    \'\'首行不缩进
        .SpaceBeforeAuto = False
        .SpaceAfterAuto = False
        .FirstLineIndent = app.CentimetersToPoints(0)
        .CharacterUnitFirstLineIndent = 0
    End With

    nDoc.SaveAs("d:\\test.doc")
    Dim fileName = "d:\\test.doc"
    \'app.Documents.Open(fileName)
    app.Documents(fileName).Range(Start:=0, End:=0).InlineShapes.AddPicture(FileName:= _
    "d:\\test2.jpg" _
    , LinkToFile:=False, SaveWithDocument:=True)
    app.Documents.save
catch ex As exception
    msgbox(ex.message)
finally
    app.Quit
End try

--  作者:有点甜
--  发布时间:2015/3/19 16:04:00
--  
 你的代码想体现什么效果啊,根本不知道你想做什么。
--  作者:pcxjxjhkw
--  发布时间:2015/3/19 16:08:00
--  
想实现:1.新建一word文档;2.插入指定文件夹下的所有图片文件,图片显示方式为嵌入型;3.设置文档格式为单倍行距,首行不缩进;4。将该文档保存到指定目录下。
[此贴子已经被作者于2015/3/19 16:08:28编辑过]