Hi,
My problem is a very peculiar one. I have a visual basic script that is added to normal.dot. The function of the VBA script is as follows.
1. An user opens a word document and saves it.
2. If the word document contains the word "Logo Thread Color Sheet" or "Logo Product Color Sheet", the document will be sent to printer for testing. It also creates a .prn file and the file will be ftp'ed to an AIX unix box.
Now my problem is while sending the document to printer.
Some of the pages are getting printed from Tray 2 and some from Tray 3. Tray 3 is for A2 size and Tray 2 is for A4 size. I need to print all the pages of the document from Tray 2 (A4 size).
Can any one help me out with this?.
I am giving the code of the VBA script below. The code is not written by me and so I will not be able to explain it in full.
==========================================================
'
' This macro is part of the process to print LOGO Color Thread Sheets for
' LE Centralized Embroidery Process.
' 1) If a document containing the text "logo color thread sheet" is saved or closed
' perform step 2 else do nothing
' 2) A .prn files is created and saved to the prn dir
' 3) The prn file is transfered to LEBO corpsales server, using a ftp batch file that
' is called from this macro
' 4) The ops cron executes ewotslp.sh on the corpsales server to print the prn files.
'
' Filename: ewo_macro_v20020716_1.bas
'
Private Const FILE_PATH_LOCAL = "S:\CORPSALES\Kids_Uniforms_Thread_Sheets"
Private Const FILE_PATH_LOCAL_PRN = FILE_PATH_LOCAL & "\PRN FILES DO NOT REMOVE\temp DO NOT REMOVE"
Private Const BATCH_FILE = FILE_PATH_LOCAL & "\EWO MACRO DO NOT REMOVE" & "\ewoftp.bat"
Private Function TrimExt(Name As String) As String
TrimExt = Left(Name, Len(Name) - 4)
End Function
Sub ewoThreadSheetSave()
'
' Main
'
Dim PrintFile
PrintFile = FILE_PATH_LOCAL_PRN & "\" & TrimExt(ActiveDocument.Name) & ".prn"
MsgBox "Print File is " & PrintFile
'Only execute on logo thread color sheets documents; search backwards else forward
Set myRange = ActiveDocument.Content
myRange.Find.Execute FindText:="LOGO THREAD COLOR SHEET", Forward:=False
myRange.Find.Execute FindText:="PRODUCT COLOR SHEET", Forward:=False
If myRange.Find.Found = True Then
MsgBox "Within If"
Call PrintToFile(PrintFile)
Call FileTransfer
Else
myRange.Find.Execute FindText:="LOGO THREAD COLOR SHEET", Forward:=True
myRange.Find.Execute FindText:="PRODUCT COLOR SHEET", Forward:=False
If myRange.Find.Found = True Then
MsgBox "With in Else"
Call PrintToFile(PrintFile)
Call FileTransfer
End If
End If
' Alternate approach to only execute on logo color thread sheet documents
' fails if document not in FILE_PATH_LOCAL and a file save as is used or the file
' is copied to the directory afterwords
'
' If ActiveDocument.Path = FILE_PATH_LOCAL Then
' Call PrintToFile(PrintFile)
' Call FileTransfer
' End If
End Sub
Sub FileTransfer()
' FileTransfer Sub
' FTP file
If Shell(BATCH_FILE, 0) = False Then
MsgBox "The call to batch file failed."
End If
End Sub
Sub PrintToFile(ByVal PrintToName As String)
'
' Create .prn file
MsgBox "In PrintToFile"
Application.PrintOut FileName:="", Range:=wdPrintAllDocument, Item:= _
wdPrintDocumentContent, Copies:=1, Pages:="", PageType:=wdPrintAllPages, _
Collate:=True, Background:=False, PrintToFile:=True, PrintZoomColumn:=0, _
PrintZoomRow:=0, PrintZoomPaperWidth:=0, PrintZoomPaperHeight:=0, _
OutputFileName:=PrintToName, Append:=False
' Set print to file back to false, with Pages:="0" will not print document
Application.PrintOut FileName:="", Range:=wdPrintRangeOfPages, Item:= _
wdPrintDocumentContent, Copies:=1, Pages:="0", PageType:=wdPrintAllPages, _
Collate:=True, Background:=True, PrintToFile:=False, PrintZoomColumn:=0, _
PrintZoomRow:=0, PrintZoomPaperWidth:=0, PrintZoomPaperHeight:=0
End Sub
Sub FileSave()
'
' FileSave Macro
' Saves the active document or template
'
MsgBox "In FileSave"
ActiveDocument.Save
Call ewoThreadSheetSave
Call ewoProductColorSheetSave
End Sub
Sub FileSaveAs()
'
' FileSaveAs Macro
' Saves a copy of the document in a separate file
'
If Dialogs(wdDialogFileSaveAs).Show = 0 Then
'MsgBox "Not Saved"
Else
'MsgBox "Saved"
'MsgBox (ActiveDocument.Name)
Call ewoThreadSheetSave
Call ewoProductColorSheetSave
End If
End Sub
Sub FileSaveAll()
'
' FileSaveAll Macro
' Saves all open files, macros, and AutoText entries, prompting for each one separately
'
Documents.Save
Call ewoThreadSheetSave
Call ewoProductColorSheetSave
End Sub
Sub AutoClose()
If ActiveDocument.Saved = False Then
If ActiveDocument.Path = FILE_PATH_LOCAL Then
If Dialogs(wdDialogFileSaveAs) = 0 Then
MsgBox "Not Saved"
Else
Call MyFileSave
End If
End If
End If
End Sub
Sub MyFileSave()
Dim Msg, Style, Title, Help, Ctxt, Response, MyString
Msg = "Do you want to save your changes to " + ActiveDocument.Name + "?" ' Define message.
Style = vbYesNoCancel + vbExclamation + vbDefaultButton1 ' Define buttons.
Title = "MsgBox Demonstration" ' Define title.
Help = "DEMO.HLP" ' Define Help file.
Ctxt = 1000 ' Define topic
' context.
' Display message.
Response = MsgBox(Msg, Style, Title, Help, Ctxt)
If Response = vbYes Then ' User chose Yes.
'MsgBox ("Yes")
'Documents.Save NoPrompt:=True
Dim PrintFile
PrintFile = FILE_PATH_LOCAL_PRN & "\" & TrimExt(ActiveDocument.Name) & ".prn"
Call PrintToFile(PrintFile)
Call FileTransfer
ElseIf Response = vbNo Then ' User chose No.
'MsgBox ("No")
ActiveDocument.ActiveWindow.Close SaveChanges:=wdDoNotSaveChanges
Else
MsgBox ("Cancel")
End If
End Sub
Sub ewoProductColorSheetSave()
'
' Main
'
Dim PrintFile
PrintFile = FILE_PATH_LOCAL_PRN & "\" & TrimExt(ActiveDocument.Name) & ".prn"
'Only execute on PRODUCT color sheets documents; search backwards else forward
Set myRange = ActiveDocument.Content
myRange.Find.Execute FindText:="PRODUCT COLORS", Forward:=False
If myRange.Find.Found = True Then
Call PrintToFile(PrintFile)
Call FileTransfer
Else
myRange.Find.Execute FindText:="PRODUCT COLORS", Forward:=True
If myRange.Find.Found = True Then
Call PrintToFile(PrintFile)
Call FileTransfer
End If
End If
End Sub
==========================================================
My problem is a very peculiar one. I have a visual basic script that is added to normal.dot. The function of the VBA script is as follows.
1. An user opens a word document and saves it.
2. If the word document contains the word "Logo Thread Color Sheet" or "Logo Product Color Sheet", the document will be sent to printer for testing. It also creates a .prn file and the file will be ftp'ed to an AIX unix box.
Now my problem is while sending the document to printer.
Some of the pages are getting printed from Tray 2 and some from Tray 3. Tray 3 is for A2 size and Tray 2 is for A4 size. I need to print all the pages of the document from Tray 2 (A4 size).
Can any one help me out with this?.
I am giving the code of the VBA script below. The code is not written by me and so I will not be able to explain it in full.
==========================================================
'
' This macro is part of the process to print LOGO Color Thread Sheets for
' LE Centralized Embroidery Process.
' 1) If a document containing the text "logo color thread sheet" is saved or closed
' perform step 2 else do nothing
' 2) A .prn files is created and saved to the prn dir
' 3) The prn file is transfered to LEBO corpsales server, using a ftp batch file that
' is called from this macro
' 4) The ops cron executes ewotslp.sh on the corpsales server to print the prn files.
'
' Filename: ewo_macro_v20020716_1.bas
'
Private Const FILE_PATH_LOCAL = "S:\CORPSALES\Kids_Uniforms_Thread_Sheets"
Private Const FILE_PATH_LOCAL_PRN = FILE_PATH_LOCAL & "\PRN FILES DO NOT REMOVE\temp DO NOT REMOVE"
Private Const BATCH_FILE = FILE_PATH_LOCAL & "\EWO MACRO DO NOT REMOVE" & "\ewoftp.bat"
Private Function TrimExt(Name As String) As String
TrimExt = Left(Name, Len(Name) - 4)
End Function
Sub ewoThreadSheetSave()
'
' Main
'
Dim PrintFile
PrintFile = FILE_PATH_LOCAL_PRN & "\" & TrimExt(ActiveDocument.Name) & ".prn"
MsgBox "Print File is " & PrintFile
'Only execute on logo thread color sheets documents; search backwards else forward
Set myRange = ActiveDocument.Content
myRange.Find.Execute FindText:="LOGO THREAD COLOR SHEET", Forward:=False
myRange.Find.Execute FindText:="PRODUCT COLOR SHEET", Forward:=False
If myRange.Find.Found = True Then
MsgBox "Within If"
Call PrintToFile(PrintFile)
Call FileTransfer
Else
myRange.Find.Execute FindText:="LOGO THREAD COLOR SHEET", Forward:=True
myRange.Find.Execute FindText:="PRODUCT COLOR SHEET", Forward:=False
If myRange.Find.Found = True Then
MsgBox "With in Else"
Call PrintToFile(PrintFile)
Call FileTransfer
End If
End If
' Alternate approach to only execute on logo color thread sheet documents
' fails if document not in FILE_PATH_LOCAL and a file save as is used or the file
' is copied to the directory afterwords
'
' If ActiveDocument.Path = FILE_PATH_LOCAL Then
' Call PrintToFile(PrintFile)
' Call FileTransfer
' End If
End Sub
Sub FileTransfer()
' FileTransfer Sub
' FTP file
If Shell(BATCH_FILE, 0) = False Then
MsgBox "The call to batch file failed."
End If
End Sub
Sub PrintToFile(ByVal PrintToName As String)
'
' Create .prn file
MsgBox "In PrintToFile"
Application.PrintOut FileName:="", Range:=wdPrintAllDocument, Item:= _
wdPrintDocumentContent, Copies:=1, Pages:="", PageType:=wdPrintAllPages, _
Collate:=True, Background:=False, PrintToFile:=True, PrintZoomColumn:=0, _
PrintZoomRow:=0, PrintZoomPaperWidth:=0, PrintZoomPaperHeight:=0, _
OutputFileName:=PrintToName, Append:=False
' Set print to file back to false, with Pages:="0" will not print document
Application.PrintOut FileName:="", Range:=wdPrintRangeOfPages, Item:= _
wdPrintDocumentContent, Copies:=1, Pages:="0", PageType:=wdPrintAllPages, _
Collate:=True, Background:=True, PrintToFile:=False, PrintZoomColumn:=0, _
PrintZoomRow:=0, PrintZoomPaperWidth:=0, PrintZoomPaperHeight:=0
End Sub
Sub FileSave()
'
' FileSave Macro
' Saves the active document or template
'
MsgBox "In FileSave"
ActiveDocument.Save
Call ewoThreadSheetSave
Call ewoProductColorSheetSave
End Sub
Sub FileSaveAs()
'
' FileSaveAs Macro
' Saves a copy of the document in a separate file
'
If Dialogs(wdDialogFileSaveAs).Show = 0 Then
'MsgBox "Not Saved"
Else
'MsgBox "Saved"
'MsgBox (ActiveDocument.Name)
Call ewoThreadSheetSave
Call ewoProductColorSheetSave
End If
End Sub
Sub FileSaveAll()
'
' FileSaveAll Macro
' Saves all open files, macros, and AutoText entries, prompting for each one separately
'
Documents.Save
Call ewoThreadSheetSave
Call ewoProductColorSheetSave
End Sub
Sub AutoClose()
If ActiveDocument.Saved = False Then
If ActiveDocument.Path = FILE_PATH_LOCAL Then
If Dialogs(wdDialogFileSaveAs) = 0 Then
MsgBox "Not Saved"
Else
Call MyFileSave
End If
End If
End If
End Sub
Sub MyFileSave()
Dim Msg, Style, Title, Help, Ctxt, Response, MyString
Msg = "Do you want to save your changes to " + ActiveDocument.Name + "?" ' Define message.
Style = vbYesNoCancel + vbExclamation + vbDefaultButton1 ' Define buttons.
Title = "MsgBox Demonstration" ' Define title.
Help = "DEMO.HLP" ' Define Help file.
Ctxt = 1000 ' Define topic
' context.
' Display message.
Response = MsgBox(Msg, Style, Title, Help, Ctxt)
If Response = vbYes Then ' User chose Yes.
'MsgBox ("Yes")
'Documents.Save NoPrompt:=True
Dim PrintFile
PrintFile = FILE_PATH_LOCAL_PRN & "\" & TrimExt(ActiveDocument.Name) & ".prn"
Call PrintToFile(PrintFile)
Call FileTransfer
ElseIf Response = vbNo Then ' User chose No.
'MsgBox ("No")
ActiveDocument.ActiveWindow.Close SaveChanges:=wdDoNotSaveChanges
Else
MsgBox ("Cancel")
End If
End Sub
Sub ewoProductColorSheetSave()
'
' Main
'
Dim PrintFile
PrintFile = FILE_PATH_LOCAL_PRN & "\" & TrimExt(ActiveDocument.Name) & ".prn"
'Only execute on PRODUCT color sheets documents; search backwards else forward
Set myRange = ActiveDocument.Content
myRange.Find.Execute FindText:="PRODUCT COLORS", Forward:=False
If myRange.Find.Found = True Then
Call PrintToFile(PrintFile)
Call FileTransfer
Else
myRange.Find.Execute FindText:="PRODUCT COLORS", Forward:=True
If myRange.Find.Found = True Then
Call PrintToFile(PrintFile)
Call FileTransfer
End If
End If
End Sub
==========================================================