PDA

View Full Version : VBA code in macro works for Word2003, won't for Word2010



jlwilde
03-01-2012, 07:40 AM
I have a macro from Word 2003 that only partially works in Word 2010. The macro prints serialization numbers on product labels to a label printer, then it should reset the default printer back and it does not in Word 2010 but did in Word 2003. If someone can assist me I will send the VB code inside the macro.

Thanks,
Jan

Anne Troy
03-02-2012, 02:36 PM
Might want to provide the code.

fumei
03-02-2012, 05:33 PM
Yes, we can not really assist without knowing what code you are using.

jlwilde
03-05-2012, 04:35 AM
Might want to provide the code.
Thank you for your response, the code is below. I do get my labels printed correctly with the bag serialization on them but then the code errors on the bottom "errhandler" where it should put the default printer back.

Sub Print_Labels_to_Printer()
'
' This macro
' Macro recorded 10/30/2009 by mcarter
'

Dim numbags As Long
Dim firstbag As Long


On Error GoTo Errhandler 'traps errors and kicks user out of the macro
ActivePrinter = "\\DIDC1\DILPR1"

'These settings turn off all spell checking, grammar, and
'smart tags. Doing so is necessary to eliminate buffering problems
'with large print files. It also ensures the labels will print in
'reverse bag numbering.

With Options
.PrintReverse = True
.DisplaySmartTagButtons = False
.CheckSpellingAsYouType = False
.CheckGrammarAsYouType = False
.SuggestSpellingCorrections = False
.SuggestFromMainDictionaryOnly = False
.CheckGrammarWithSpelling = False
End With

'These commands open the data source that contains the bag numbers.
'The data source is mapped to the <<bag_number>> field on the labels.

ActiveDocument.MailMerge.OpenDataSource Name:= _
"I:\DATA CONF\BagSequenceListReverse.xls", _
ConfirmConversions:=False, ReadOnly:=False, LinkToSource:=True, _
AddToRecentFiles:=False, PasswordDocument:="", PasswordTemplate:="", _
WritePasswordDocument:="", WritePasswordTemplate:="", Revert:=False, _
Format:=wdOpenFormatAuto, Connection:= _
"Provider=Microsoft.Jet.OLEDB.4.0;Password="""";User ID=Admin;Data Source=C:\Documents and Settings\mcarter\Desktop\sequence.xls;Mode=Read;Extended Properties=""HDR=YES;IMEX=1;"";Jet OLEDB:System database="""";Jet OLEDB:Registry Path="""";Jet OLEDB:Database Passwo" _
, SQLStatement:="SELECT * FROM `Bag_Counter$`", SQLStatement1:="", SubType:= _
wdMergeSubTypeAccess

'These commands execute the MailMerge function and generates copies of
'the labels - each with a sequential bag number.

numbags = InputBox("Number of bag labels?")
firstbag = InputBox("Starting bag number?")

With ActiveDocument.MailMerge
.Destination = wdSendToPrinter
.SuppressBlankLines = True
With .DataSource
.LastRecord = 5000 - firstbag + 1 'starting bag number
.FirstRecord = .LastRecord - numbags + 1 'ending bag number
End With
MsgBox ("Press OK to print labels " & firstbag & " through " & (firstbag + numbags - 1) & ".")
.Execute Pause:=False
End With
ActivePrinter = "HP LaserJet 1100 (MS)"
CommandBars("Mail Merge").Visible = False
CommandBars("Visual Basic").Visible = False
Errhandler:
ActivePrinter = "HP LaserJet 1100 (MS)"
'MsgBox ("An error occurred, please try again.")

'activeDocument.Close
End Sub

Thanks again for responding :yes

jlwilde
03-05-2012, 07:16 AM
Thank you all for trying to assist, but problem has been solved. I was given the following code from another forum and it now works. Unforturately this site will not let me post the new code for others to read. I will try later to get it posted.

Thanks again