?
Solved

Word 97 Macro, Not running correctly in word 2000

Posted on 2003-03-31
3
Medium Priority
?
825 Views
Last Modified: 2012-06-21
Hi,

I have a problem with a macro I wrote many moons ago. The problem is I struggled to get it working at the time and haven't touched it since as it worked quite well.

I have upgraded to office 2000 now and the problems I am getting are as follows:

Microsoft word err=1120
There is a printer error

A couple of things to note, the printer is connected locally and is called 'local'. There is also a mapping to h:\ locally. Tray 2 is also full of paper and I can print from here normally.

Ideally I'd like to change it so that the documents print to a network printer. One other thing is sometimes I get an error that the margins are outside the printable area of the page. Is there any way I can bypass this? If anybody could point me in the right direction I'd really appreciate it.....

The code is as follows:

Public Sub MAIN()
Dim Y$
Dim D$
Dim S$
Dim num$
Dim Count_
Dim logname$
Y$ = WordBasic.[Date$](WordBasic.Today() - 1)
D$ = WordBasic.[Date$](WordBasic.Today())
S$ = "h:\dummy.doc"

WordBasic.FileFind SearchName:="dummy", SearchPath:=S$, Name:="*.doc", SubDir:=0, Title:="", Author:="", Keywords:="", Subject:="", Options:=0, MatchCase:=0, Text:="", PatternMatch:=0, DateSavedFrom:=Y$, DateSavedTo:=Y$, SavedBy:="", DateCreatedFrom:="", DateCreatedTo:="", View:=0, SortBy:=4, ListBy:=0, SelectedFile:=0



WordBasic.FileNewDefault
WordBasic.FormatFont Points:=18, Underline:=1, Bold:=1
WordBasic.InsertDateField
WordBasic.Insert Chr(32)
WordBasic.Insert "                                 Dummy Dept (1st Floor) Documents"
WordBasic.Insert Chr(13)
WordBasic.Insert Chr(13)
WordBasic.Insert "                                           Total Documents printed =  "
WordBasic.Insert Chr(32)
num$ = WordBasic.[LTrim$](Str(WordBasic.CountFoundFiles()))
WordBasic.Insert num$
WordBasic.Insert Chr(13)
WordBasic.Insert Chr(13)
WordBasic.Insert Chr(13)
WordBasic.FormatTabs Position:="7.5 cm", Align:=0, Set:=1

Count_ = 0
On Error GoTo -1: On Error GoTo Finish
While Count_ <= WordBasic.CountFoundFiles()
    Count_ = Count_ + 1
    WordBasic.Insert WordBasic.[FoundFileName$](Count_)
    If Count_ / 2 <> WordBasic.Int(Count_ / 2) Then
    WordBasic.Insert Chr(9)
    Else
    WordBasic.Insert Chr(13)
    End If
Wend

logname$ = "H:\dummy.doc"
WordBasic.FileSaveAs Name:=logname$

WordBasic.FilePrintSetup Printer:="local"
WordBasic.ToolsOptionsPrint DefaultTray:="Tray 2"
WordBasic.FilePrint Background:=0, AppendPrFile:=0, Range:="0", PrToFileName:="", From:="", To:="", Type:=0, NumCopies:="1", Pages:="", Order:=0, PrintToFile:=0, Collate:=1, FileName:="H:\dummy.doc"


Count_ = 0
On Error GoTo -1: On Error GoTo Finish
While Count_ <= WordBasic.CountFoundFiles()
    Count_ = Count_ + 1
WordBasic.FilePrintSetup Printer:="Local"
WordBasic.ToolsOptionsPrint DefaultTray:="Tray 2"
WordBasic.FilePrint Background:=0, AppendPrFile:=0, Range:="0", PrToFileName:="", From:="", To:="", Type:=0, NumCopies:="1", Pages:="", Order:=0, PrintToFile:=0, Collate:=1, FileName:=WordBasic.[FoundFileName$](Count_)
Wend
Finish:
WordBasic.FileExit 1
End Sub


0
Comment
Question by:retro_questions
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
3 Comments
 
LVL 76

Expert Comment

by:GrahamSkan
ID: 8238459
I only get that error if it can't find the printer. Just changing the "Local" for our network print name got it working here.

You could drop the WordBasic and use the VBA equivalents:

ActivePrinter = "Network printer name"
Options.DefaultTray = "Tray 1"
ActiveDocument.PrintOut

0
 
LVL 76

Accepted Solution

by:
GrahamSkan earned 150 total points
ID: 8238760
Regarding the margins outside printable area. Have you checked both the margins in the Word Page Layout and those in the Printer Properties?
0
 

Expert Comment

by:CleanupPing
ID: 8531271
Hi retro_questions,
This old question (QID 20568554) needs to be finalized -- accept an answer, split points, or get a refund.  Please see http://www.cityofangels.com/Experts/Closing.htm for information and options.
0

Featured Post

On Demand Webinar: Networking for the Cloud Era

Ready to improve network connectivity? Watch this webinar to learn how SD-WANs and a one-click instant connect tool can boost provisions, deployment, and management of your cloud connection.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Enums (shorthand for ‘enumerations’) are not often used by programmers but they can be quite valuable when they are.  What are they? An Enum is just a type of variable like a string or an Integer, but in this case one that you create that contains…
You can of course define an array to hold data that is of a particular type like an array of Strings to hold customer names or an array of Doubles to hold customer sales, but what do you do if you want to coordinate that data? This article describes…
Get people started with the utilization of class modules. Class modules can be a powerful tool in Microsoft Access. They allow you to create self-contained objects that encapsulate functionality. They can easily hide the complexity of a process from…
This lesson covers basic error handling code in Microsoft Excel using VBA. This is the first lesson in a 3-part series that uses code to loop through an Excel spreadsheet in VBA and then fix errors, taking advantage of error handling code. This l…
Suggested Courses
Course of the Month12 days, 6 hours left to enroll

752 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question