I'm trying to make a simple macro in Excel to compare a students spreadsheet to an answer one I have saved.
To do this, I am currently saving the spreadsheets as web pages, opening them in Word, and doing a merge and compare.
This works fine except that I need it to print the merged document in landscape and on 1 page, but I can't seem to get it to change the orientation.
Sub Marking_Unit2_Mock()
' Save the student spreadsheet as a web page
ActiveWorkbook.SaveAs Filename:= _
"\\Websvr\Transfer Folder\Unit2_Mock\caffcost_student_web.htm", FileFormat:= _
xlHtml, ReadOnlyRecommended:=False, CreateBackup:=False
Workbooks.Open Filename:="\\Websvr\Transfer Folder\Unit2_Mock\caffcoststudent.xls"
' Open the answer spreadsheet and save as a web page
Workbooks.Open Filename:="\\Websvr\Transfer Folder\Unit2_Mock\caffcost.xls"
ActiveWorkbook.SaveAs Filename:= _
"\\Websvr\Transfer Folder\Unit2_Mock\caffcost_answers_web.htm", FileFormat:= _
xlHtml, ReadOnlyRecommended:=False, CreateBackup:=False
ActiveWindow.Close
' Open the answer web page in Word and compare to the student web page
Set wrdApp = CreateObject("Word.Application"
wrdApp.Visible = True
wrdApp.Documents.Open Filename:="\\Websvr\Transfer Folder\Unit2_Mock\caffcost_answers_web.htm"
wrdApp.ActiveDocument.Compare Name:= _
"\\Websvr\Transfer Folder\Unit2_Mock\caffcost_student_web.htm"
' Save the compared document and print
wrdApp.ActiveDocument.SaveAs Filename:="\\Websvr\Transfer Folder\Unit2_Mock\caffcost_compared" & ".doc"
wrdApp.ActiveDocument.Close
wrdApp.Documents.Open Filename:="\\Websvr\Transfer Folder\Unit2_Mock\caffcost_compared.doc"
wrdApp.ActivePrinter = "HP LaserJet 4100 PCL 6"
With wrdApp.ActiveDocument.PageSetup
.Orientation = wdOrientLandscape
End With
wrdApp.Application.PrintOut Filename:="\\Websvr\Transfer Folder\Unit2_Mock\caffcost_compared.doc"
wrdApp.ActiveWindow.Close savechanges:=wdDoNotSaveChanges
wrdApp.ActiveWindow.Close
End Sub
Could anyone help me out?
ps. I'm using XP, and another small problem I've encountered is that if I merge and compare into a new document, and try to save and print the result, it will print the original document before the comparison, unless I save, close, re-open the document and then print. Although this gets round the problem, does anyone know a way of getting it to print the compared document without having to do this?
To do this, I am currently saving the spreadsheets as web pages, opening them in Word, and doing a merge and compare.
This works fine except that I need it to print the merged document in landscape and on 1 page, but I can't seem to get it to change the orientation.
Sub Marking_Unit2_Mock()
' Save the student spreadsheet as a web page
ActiveWorkbook.SaveAs Filename:= _
"\\Websvr\Transfer Folder\Unit2_Mock\caffcost_student_web.htm", FileFormat:= _
xlHtml, ReadOnlyRecommended:=False, CreateBackup:=False
Workbooks.Open Filename:="\\Websvr\Transfer Folder\Unit2_Mock\caffcoststudent.xls"
' Open the answer spreadsheet and save as a web page
Workbooks.Open Filename:="\\Websvr\Transfer Folder\Unit2_Mock\caffcost.xls"
ActiveWorkbook.SaveAs Filename:= _
"\\Websvr\Transfer Folder\Unit2_Mock\caffcost_answers_web.htm", FileFormat:= _
xlHtml, ReadOnlyRecommended:=False, CreateBackup:=False
ActiveWindow.Close
' Open the answer web page in Word and compare to the student web page
Set wrdApp = CreateObject("Word.Application"
wrdApp.Visible = True
wrdApp.Documents.Open Filename:="\\Websvr\Transfer Folder\Unit2_Mock\caffcost_answers_web.htm"
wrdApp.ActiveDocument.Compare Name:= _
"\\Websvr\Transfer Folder\Unit2_Mock\caffcost_student_web.htm"
' Save the compared document and print
wrdApp.ActiveDocument.SaveAs Filename:="\\Websvr\Transfer Folder\Unit2_Mock\caffcost_compared" & ".doc"
wrdApp.ActiveDocument.Close
wrdApp.Documents.Open Filename:="\\Websvr\Transfer Folder\Unit2_Mock\caffcost_compared.doc"
wrdApp.ActivePrinter = "HP LaserJet 4100 PCL 6"
With wrdApp.ActiveDocument.PageSetup
.Orientation = wdOrientLandscape
End With
wrdApp.Application.PrintOut Filename:="\\Websvr\Transfer Folder\Unit2_Mock\caffcost_compared.doc"
wrdApp.ActiveWindow.Close savechanges:=wdDoNotSaveChanges
wrdApp.ActiveWindow.Close
End Sub
Could anyone help me out?
ps. I'm using XP, and another small problem I've encountered is that if I merge and compare into a new document, and try to save and print the result, it will print the original document before the comparison, unless I save, close, re-open the document and then print. Although this gets round the problem, does anyone know a way of getting it to print the compared document without having to do this?