当前位置: 动力学知识库 > 问答 > 编程问答 >

python - VB Script : how to save the output file of a word macro as an ANSI encoded raw file with UNIX eol?

问题描述:

Based on another question, that I asked here :

How to insert a macro in a Word-VBA using python?

The output of the word Macro is a .doc file.

I manually have to copy the contents of this .doc file using ctrlA+ctrlC and then copy it using ctrlV in a Text editor(Notepad++)

Thereafter , when saving the file , I use ANSI Encoding, and goto the EOL ,to select UNIX EOL.

What I need to do, is convert the above manual process to be a part of my vb script.

Sub MergeDocs1()

Dim rng As Range

Dim MainDoc As Document

Dim strFile As String

Const strFolder = "d:\Userfiles\msultana\Desktop\PRORATION\PMP_Automation\PMP_June\" 'change to suit

Set MainDoc = Documents.Add

strFile = Dir$(strFolder & "*.doc") ' can change to .docx

Do Until strFile = ""

Set rng = MainDoc.Range

rng.Collapse wdCollapseEnd

rng.InsertFile strFolder & strFile

rng.InsertAfter vbCrLf

strFile = Dir$()

Loop

MsgBox ("Files are merged")

' Accept all tracking changes (PTR 10078844)

Dim stry As Object

For Each stry In ActiveDocument.StoryRanges

If stry.Revisions.Count >= 1 Then _

stry.Revisions.AcceptAll

Next

' Save file in new format

ActiveDocument.SaveAs2 FileName:="proviso.raw.June2016", _

FileFormat:=wdFormatDOSText, _

LineEnding:=wdLFOnly

MsgBox ("Save file in new format ANSI UNIX EOL")

End Sub

However, the file size and format differ when I try to do this manually, and by using the VB Script above.I have tried that below.

Can you please help me improve this script and/or correct it ?

Since I am calling this macro from a python script, I am also open to solutions from python as well.

I am new to macros and VB script.

分享给朋友:
您可能感兴趣的文章:
随机阅读: