Jump to content

Recommended Posts

Posted (edited)

Ok man this thing is insane. This is mostly untested except for the functions that I wrote. And I'm only including enough code to convert your first 5 reports. Once you get it working you can figure out the rest.

#include "doc2pdf.au3"
#include <Array.au3>

;Global Constants
Const $ROOTIN = "\\P533FP2\MATCTRL_REPORTS\208-280TH (METNAV)\"
Const $ROOTOUT = "\\P533FP2\45SW_ERM\45SCS_SCBMM\"


;Priority Report D23
$PathArray[12][2] = [["JANUARY 07","15 - Priority Monitor Report\15-B - D231 January"], _
                    ["FEBRUARY 07","15 - Priority Monitor Report\15-B - D232 February"], _
                    ["MARCH 07", "15 - Priority Monitor Report\15-B - D233 March"], _
                    ["APRIL 07","15 - Priority Monitor Report\15-B - D234 April"], _
                    ["MAY 07", "15 - Priority Monitor Report\15-B - D235 May"], _               
                    ["JUNE 07","15 - Priority Monitor Report\15-B - D236 June"], _
                    ["july 07", "15 - Priority Monitor Report\15-B - D237 July"], _
                    ["august 07","15 - Priority Monitor Report\15-B - D238 August"], _
                    ["september 07", "15 - Priority Monitor Report\15-B - D239 September"], _
                    ["october 07","15 - Priority Monitor Report\15-B - D23\10 October"], _
                    ["november 07", "15 - Priority Monitor Report\15-B - D23\11 November"], _
                    ["december 07","15 - Priority Monitor Report\15-B - D23\12 December"], _
                    ]

convertmultiplefolders($PathArray, "11-04. D23 Daily Report*.doc")

;Priority report Q13
$PathArray[12][2] = [["JANUARY 07","15 - Priority Monitor Report\15-D - S041 January"], _
                    ["FEBRUARY 07","15 - Priority Monitor Report\15-D - S042 February"], _
                    ["MARCH 07", "15 - Priority Monitor Report\15-D - S043 March"], _
                    ["APRIL 07","15 - Priority Monitor Report\15-D - S044 April"], _
                    ["MAY 07", "15 - Priority Monitor Report\15-D - S045 May"], _               
                    ["JUNE 07","15 - Priority Monitor Report\15-D - S046 June"], _
                    ["july 07", "15 - Priority Monitor Report\15-D - S047 July"], _
                    ["august 07","15 - Priority Monitor Report\15-D - S048 August"], _
                    ["september 07", "15 - Priority Monitor Report\15-D - S049 September"], _
                    ["october 07","15 - Priority Monitor Report\15-D - S04\10 October"], _
                    ["november 07", "15 - Priority Monitor Report\15-D - S04\11 November"], _
                    ["december 07","15 - Priority Monitor Report\15-D - S04\12 December"], _
                    ]

convertmultiplefolders($PathArray, "SP03.txt")

;Priority report D18
$PathArray[12][2] = [["JANUARY 07","15 - Priority Monitor Report\15-A - D181 January"], _
                    ["FEBRUARY 07","15 - Priority Monitor Report\15-A - D182 February"], _
                    ["MARCH 07", "15 - Priority Monitor Report\15-A - D183 March"], _
                    ["APRIL 07","15 - Priority Monitor Report\15-A - D184 April"], _
                    ["MAY 07", "15 - Priority Monitor Report\15-A - D185 May"], _               
                    ["JUNE 07","15 - Priority Monitor Report\15-A - D186 June"], _
                    ["july 07", "15 - Priority Monitor Report\15-A - D187 July"], _
                    ["august 07","15 - Priority Monitor Report\15-A - D188 August"], _
                    ["september 07", "15 - Priority Monitor Report\15-A - D189 September"], _
                    ["october 07","15 - Priority Monitor Report\15-A - D18\10 October"], _
                    ["november 07", "15 - Priority Monitor Report\15-A - D18\11 November"], _
                    ["december 07","15 - Priority Monitor Report\15-A - D18\12 December"], _
                    ]

convertmultiplefolders($PathArray, "11-03. D18 Daily Report*.doc")

;Priority Report M30
$PathArray[12][2] = [["JANUARY 07","15 - Priority Monitor Report\15-F - M301 January"], _
                    ["FEBRUARY 07","15 - Priority Monitor Report\15-F - M302 February"], _
                    ["MARCH 07", "15 - Priority Monitor Report\15-F - M303 March"], _
                    ["APRIL 07","15 - Priority Monitor Report\15-F - M304 April"], _
                    ["MAY 07", "15 - Priority Monitor Report\15-F - M305 May"], _               
                    ["JUNE 07","15 - Priority Monitor Report\15-F - M306 June"], _
                    ["july 07", "15 - Priority Monitor Report\15-F - M307 July"], _
                    ["august 07","15 - Priority Monitor Report\15-F - M308 August"], _
                    ["september 07", "15 - Priority Monitor Report\15-F - M309 September"], _
                    ["october 07","15 - Priority Monitor Report\15-F - M30\10 October"], _
                    ["november 07", "15 - Priority Monitor Report\15-F - M30\11 November"], _
                    ["december 07","15 - Priority Monitor Report\15-F - M30\12 December"], _
                    ]

convertmultiplefolders($PathArray, "11-08. M30 Report*.doc")

;Daily Document Register (D04)
$PathArray[12][2] = [["JANUARY 07","21 - Daily Document Registers\21-A - D041 January"], _
                    ["FEBRUARY 07","21 - Daily Document Registers\21-A - D042 February"], _
                    ["MARCH 07", "21 - Daily Document Registers\21-A - D043 March"], _
                    ["APRIL 07","21 - Daily Document Registers\21-A - D044 April"], _
                    ["MAY 07", "21 - Daily Document Registers\21-A - D045 May"], _          
                    ["JUNE 07","21 - Daily Document Registers\21-A - D046 June"], _
                    ["july 07", "21 - Daily Document Registers\21-A - D047 July"], _
                    ["august 07","21 - Daily Document Registers\21-A - D048 August"], _
                    ["september 07", "21 - Daily Document Registers\21-A - D049 September"], _
                    ["october 07","21 - Daily Document Registers\21-A - D04\10 October"], _
                    ["november 07", "21 - Daily Document Registers\21-A - D04\11 November"], _
                    ["december 07","21 - Daily Document Registers\21-A - D04\12 December"], _
                    ]

convertmultiplefolders($PathArray, "11-01. D04, Daily Report*.doc")

;----------------------------------------------
; FUNCTIONS
;----------------------------------------------

;Convert all folders in an array
Func convertmultiplefolders(ByRef $PathArray, $filter)
    For $X = 0 to Ubound($PathArray) - 1
        convertfolder($ROOTIN & $PathArray[$X][0], $ROOTOUT & $PathArray[$X][1], $filter)
    Next
EndFunc

;Convert all files in a single folder
Func convertfolder($DocPath, $PdfPath, $filter)

    ;Retrieve array of doc files
    $DocArray = _FileListToArray ( $DocPath, $filter,1)

    ;_ArrayDisplay($DocArray)

    For $X = 1 to $DocArray[0]
        $inFile = $DocPath & "\" & $DocArray[$X]
        $outFile = $PdfPath & "\" & StringTrimRight ($DocArray[$X], 3 ) & "pdf"
        ;MsgBox(0,"","IN: " & $inFile & @CRLF & "OUT: " & $outFile)
        ;Comment this out to simulate
        DOC2PDF($inFile, $outFile)
    Next
EndFunc
Edited by weaponx
  • Replies 62
  • Created
  • Last Reply

Top Posters In This Topic

Top Posters In This Topic

Posted

Ok man this thing is insane. This is mostly untested except for the functions that I wrote. And I'm only including enough code to convert your first 5 reports. Once you get it working you can figure out the rest.

#include "doc2pdf.au3"
#include <Array.au3>

;Global Constants
Const $ROOTIN = "\\P533FP2\MATCTRL_REPORTS\208-280TH (METNAV)\"
Const $ROOTOUT = "\\P533FP2\45SW_ERM\45SCS_SCBMM\"
;Priority Report D23
$PathArray[12][2] = [["JANUARY 07","15 - Priority Monitor Report\15-B - D231 January"], _
                    ["FEBRUARY 07","15 - Priority Monitor Report\15-B - D232 February"], _
                    ["MARCH 07", "15 - Priority Monitor Report\15-B - D233 March"], _
                    ["APRIL 07","15 - Priority Monitor Report\15-B - D234 April"], _
                    ["MAY 07", "15 - Priority Monitor Report\15-B - D235 May"], _               
                    ["JUNE 07","15 - Priority Monitor Report\15-B - D236 June"], _
                    ["july 07", "15 - Priority Monitor Report\15-B - D237 July"], _
                    ["august 07","15 - Priority Monitor Report\15-B - D238 August"], _
                    ["september 07", "15 - Priority Monitor Report\15-B - D239 September"], _
                    ["october 07","15 - Priority Monitor Report\15-B - D23\10 October"], _
                    ["november 07", "15 - Priority Monitor Report\15-B - D23\11 November"], _
                    ["december 07","15 - Priority Monitor Report\15-B - D23\12 December"], _
                    ]

convertmultiplefolders($PathArray, "11-04. D23 Daily Report*.doc")

;Priority report Q13
$PathArray[12][2] = [["JANUARY 07","15 - Priority Monitor Report\15-D - S041 January"], _
                    ["FEBRUARY 07","15 - Priority Monitor Report\15-D - S042 February"], _
                    ["MARCH 07", "15 - Priority Monitor Report\15-D - S043 March"], _
                    ["APRIL 07","15 - Priority Monitor Report\15-D - S044 April"], _
                    ["MAY 07", "15 - Priority Monitor Report\15-D - S045 May"], _               
                    ["JUNE 07","15 - Priority Monitor Report\15-D - S046 June"], _
                    ["july 07", "15 - Priority Monitor Report\15-D - S047 July"], _
                    ["august 07","15 - Priority Monitor Report\15-D - S048 August"], _
                    ["september 07", "15 - Priority Monitor Report\15-D - S049 September"], _
                    ["october 07","15 - Priority Monitor Report\15-D - S04\10 October"], _
                    ["november 07", "15 - Priority Monitor Report\15-D - S04\11 November"], _
                    ["december 07","15 - Priority Monitor Report\15-D - S04\12 December"], _
                    ]

convertmultiplefolders($PathArray, "SP03.txt")

;Priority report D18
$PathArray[12][2] = [["JANUARY 07","15 - Priority Monitor Report\15-A - D181 January"], _
                    ["FEBRUARY 07","15 - Priority Monitor Report\15-A - D182 February"], _
                    ["MARCH 07", "15 - Priority Monitor Report\15-A - D183 March"], _
                    ["APRIL 07","15 - Priority Monitor Report\15-A - D184 April"], _
                    ["MAY 07", "15 - Priority Monitor Report\15-A - D185 May"], _               
                    ["JUNE 07","15 - Priority Monitor Report\15-A - D186 June"], _
                    ["july 07", "15 - Priority Monitor Report\15-A - D187 July"], _
                    ["august 07","15 - Priority Monitor Report\15-A - D188 August"], _
                    ["september 07", "15 - Priority Monitor Report\15-A - D189 September"], _
                    ["october 07","15 - Priority Monitor Report\15-A - D18\10 October"], _
                    ["november 07", "15 - Priority Monitor Report\15-A - D18\11 November"], _
                    ["december 07","15 - Priority Monitor Report\15-A - D18\12 December"], _
                    ]

convertmultiplefolders($PathArray, "11-03. D18 Daily Report*.doc")

;Priority Report M30
$PathArray[12][2] = [["JANUARY 07","15 - Priority Monitor Report\15-F - M301 January"], _
                    ["FEBRUARY 07","15 - Priority Monitor Report\15-F - M302 February"], _
                    ["MARCH 07", "15 - Priority Monitor Report\15-F - M303 March"], _
                    ["APRIL 07","15 - Priority Monitor Report\15-F - M304 April"], _
                    ["MAY 07", "15 - Priority Monitor Report\15-F - M305 May"], _               
                    ["JUNE 07","15 - Priority Monitor Report\15-F - M306 June"], _
                    ["july 07", "15 - Priority Monitor Report\15-F - M307 July"], _
                    ["august 07","15 - Priority Monitor Report\15-F - M308 August"], _
                    ["september 07", "15 - Priority Monitor Report\15-F - M309 September"], _
                    ["october 07","15 - Priority Monitor Report\15-F - M30\10 October"], _
                    ["november 07", "15 - Priority Monitor Report\15-F - M30\11 November"], _
                    ["december 07","15 - Priority Monitor Report\15-F - M30\12 December"], _
                    ]

convertmultiplefolders($PathArray, "11-08. M30 Report*.doc")

;Daily Document Register (D04)
$PathArray[12][2] = [["JANUARY 07","21 - Daily Document Registers\21-A - D041 January"], _
                    ["FEBRUARY 07","21 - Daily Document Registers\21-A - D042 February"], _
                    ["MARCH 07", "21 - Daily Document Registers\21-A - D043 March"], _
                    ["APRIL 07","21 - Daily Document Registers\21-A - D044 April"], _
                    ["MAY 07", "21 - Daily Document Registers\21-A - D045 May"], _          
                    ["JUNE 07","21 - Daily Document Registers\21-A - D046 June"], _
                    ["july 07", "21 - Daily Document Registers\21-A - D047 July"], _
                    ["august 07","21 - Daily Document Registers\21-A - D048 August"], _
                    ["september 07", "21 - Daily Document Registers\21-A - D049 September"], _
                    ["october 07","21 - Daily Document Registers\21-A - D04\10 October"], _
                    ["november 07", "21 - Daily Document Registers\21-A - D04\11 November"], _
                    ["december 07","21 - Daily Document Registers\21-A - D04\12 December"], _
                    ]

convertmultiplefolders($PathArray, "11-01. D04, Daily Report*.doc")

;----------------------------------------------
; FUNCTIONS
;----------------------------------------------

;Convert all folders in an array
Func convertmultiplefolders(ByRef $PathArray, $filter)
    For $X = 0 to Ubound($PathArray) - 1
        convertfolder($ROOTIN & $PathArray[$X][0], $ROOTOUT & $PathArray[$X][1], $filter)
    Next
EndFunc

;Convert all files in a single folder
Func convertfolder($DocPath, $PdfPath, $filter)

    ;Retrieve array of doc files
    $DocArray = _FileListToArray ( $DocPath, $filter,1)

    ;_ArrayDisplay($DocArray)

    For $X = 1 to $DocArray[0]
        $inFile = $DocPath & "\" & $DocArray[$X]
        $outFile = $PdfPath & "\" & StringTrimRight ($DocArray[$X], 3 ) & "pdf"
        ;MsgBox(0,"","IN: " & $inFile & @CRLF & "OUT: " & $outFile)
        ;Comment this out to simulate
        DOC2PDF($inFile, $outFile)
    Next
EndFunc

I am gonna try this this afternoon. I'll post the results. Thanks for your help.

  • Moderators
Posted

This should do what you need.

#include <IE.au3>
#include <Word.au3>

;WdSaveFormat Constants New to Word 2007
Const $wdFormatXMLDocument = 12
Const $wdFormatXMLDocumentMacroEnabled = 13
Const $wdFormatXMLTemplate = 14
Const $wdFormatXMLTemplateMacroEnabled = 15
Const $wdFormatDocumentDefault = 16
Const $wdFormatPDF = 17
Const $wdFormatXPS = 18
Const $wdFormatFlatXML = 19
Const $wdFormatFlatXMLMacroEnabled = 20
Const $wdFormatFlatXMLTemplate = 21
Const $wdFormatFlatXMLTemplateMacroEnabled = 22

; Path to the directory containing the .doc files
$sDocPath = "c:\test\"
; Destination directory for the .pdf files
$sPDFPath = "c:\test\PDF\"
;Verify the destination directory exists
DirCreate($sPDFPath)

; Register the default Word.au3 COM Error Handler
_WordErrorHandlerRegister()
; Create an invisible MS Word Application
$oWordApp = _WordCreate("", 0, 0)

; Searches for filenames of all .doc files in the specified directory.
$search = FileFindFirstFile($sDocPath & "*.doc?")
; Check if the search was successful
If $search = -1 Then
    MsgBox(0, "Error", "No files/directories matched the search pattern")
    Exit
EndIf

While 1
    $file = FileFindNextFile($search)
    If @error Then ExitLoop

    $oDoc = _WordDocOpen($oWordApp, $sDocPath & $file)
    If @error Then
        MsgBox(0, "Error", "There was an error trying to open " & $file)
        ContinueLoop
    EndIf
    $sPDFName = StringTrimRight($file, (StringLen($file) - StringInStr($file, ".", False, -1) + 1)) & ".pdf"
    _WordDocSaveAs($oDoc, $sPDFPath & $sPDFName, $wdFormatPDF)
    If @error And $WordComErrorNumber = -2147352567 Then
        MsgBox(0, "Error", 'You first need to install the "2007 Microsoft Office Add-in: Microsoft Save as PDF".' & @CRLF & @CRLF & _
                "The download link will now be opened for you.")
        _IECreate("http://www.microsoft.com/downloads/details.aspx?FamilyId=F1FC413C-6D89-4F15-991B-63B07BA5F2E5&displaylang=en", 0, 1, 0)
        ExitLoop
    EndIf
    _WordDocClose($oDoc, 0)
WEnd

; Close the search handle
FileClose($search)
; Close the MS Word Application
_WordQuit($oWordApp, 0)
Posted

Big_daddy I like your idea but if you look at post #9 (ORIGINALcopyreports.au3) his input subfolder names do not match the output subfolder names, thats the only reason I used 2-dimensional arrays for in and out, also the file filter changes for each report.

Otherwise I would have just grabbed all the folder names into an array and used them for both input and output.

Posted

Thanks guys I haven't had a chance to test it here at work yet. But Hopefully I can get to it today. Weapon I will use the new versions that you posted. I will post the results here.

Posted

The forum must have stripped some slashes because the $pathArray paths look wrong, I will attach the file.

I also have attached the updated doc2pdf.au3

doc2pdf.au3

WeaponXconvertfolders.au3

One quick question though... on script it states #include array.au3. Where is that script? I assume that when I run the script that it is going to call the script that should be included. But I don't recall having that script.
  • Moderators
Posted

Big_daddy I like your idea but if you look at post #9 (ORIGINALcopyreports.au3) his input subfolder names do not match the output subfolder names, thats the only reason I used 2-dimensional arrays for in and out, also the file filter changes for each report.

Otherwise I would have just grabbed all the folder names into an array and used them for both input and output.

I was just trying to show how it could be done with the existing Word functions.
Posted

array.au3 is included with autoit, it just finds it in the AutoIT includes directory. No need to do anything.

Posted

array.au3 is included with autoit, it just finds it in the AutoIT includes directory. No need to do anything.

Oh ok. Now what if I Don't have autoit installed on this pc? I ask because we are not allowed to have autoit installed on the pc, but I can run the script from an .exe file. If it is going to call the array.au3 then I would think I would need it on this pc. Is there away to take all three scrips and combine them into one .exe file?

On a side note I still havent gotten a chance to really focus on testing it due to work issues, but I will get it tested. However, upon testing it I will be looking into compiling it because it will have to be compiled for me to use since autoit isn't installed and the OS wont recognize the .au3 file. But it will use the .exe compiled version without a problem.

Posted

The forum must have stripped some slashes because the $pathArray paths look wrong, I will attach the file.

I also have attached the updated doc2pdf.au3

doc2pdf.au3

WeaponXconvertfolders.au3

I am getting an error when I run it both compiled, and in scite:

scite:

>C:\Program Files\AutoIt3\SciTE\..\au3check.exe "C:\Documents and Settings\webbdam\Desktop\WeaponXconvertfolders.au3"

AutoIt3 Syntax Checker v1.54.8 Copyright © Tylo 2007

C:\Documents and Settings\webbdam\Desktop\WeaponXconvertfolders.au3(10,21) : ERROR: syntax error

$PathArray[12][2] = [

~~~~~~~~~~~~~~~~~~~~^

Compiled:

Posted Image

Posted

I am getting an error when I run it both compiled, and in scite:

scite:

>C:\Program Files\AutoIt3\SciTE\..\au3check.exe "C:\Documents and Settings\webbdam\Desktop\WeaponXconvertfolders.au3"

AutoIt3 Syntax Checker v1.54.8 Copyright © Tylo 2007

C:\Documents and Settings\webbdam\Desktop\WeaponXconvertfolders.au3(10,21) : ERROR: syntax error

$PathArray[12][2] = [

~~~~~~~~~~~~~~~~~~~~^

Compiled:

Posted Image

-bump

Any idea about this?

Posted (edited)

The multidimensional arrays were declared wrong in the original file I sent, remember I can't test everything since I don't have the same folder structure. I'll post a tested version soon.

Edited by weaponx
Posted

The multidimensional arrays were declared wrong in the original file I sent, remember I can't test everything since I don't have the same folder structure. I'll post a tested version soon.

Thats cool. I will keep an eye out.

Posted

Okay here we go:

I am also attaching the required includes from AutoIT since you said you can't install it:

Alright I added a simple gui to this so you could see some status. Everything tested okay.

Posted

Okay here we go:

I am also attaching the required includes from AutoIT since you said you can't install it:

Alright I added a simple gui to this so you could see some status. Everything tested okay.

Ok. thanks checking it out now.

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...