#1
|
|||
|
|||
Compile error -- incompatibility?
I am not a coder. I've into a problem with a colleague after walking him through installation of a macro over the phone.
When he runs it, he's getting a message of a compile error and "Method or data member not found." In VB, the first line, with the macro name, is highlighted with a yellow pointer, and teh line ".NumberSpacing = wdNumberSpacingDefault" is highlighted in blue. He is using Word 2007. Could this be a compatibility error? Here is the code: Code:
Sub EIRPreEdit() ' ' Macro to format the entire document to Times New Roman 14 pt 6/6, single space, left-aligned ' replace straight single and double straight quotes with curly, and transpose commas and periods to inside of close quote ' remove tabs; ' replace two or more consecutive character spaces with a single one ' replace manual line returns with hard returns; and ' remove empty paragraphs ' ' Selection.WholeStory With Selection.Font .Name = "Times New Roman" .Color = wdColorAutomatic .Size = 14 .Spacing = 0 .Scaling = 100 .Position = 0 .Kerning = 0 .NumberSpacing = wdNumberSpacingDefault .NumberForm = wdNumberFormDefault .StylisticSet = wdStylisticSetDefault .ContextualAlternates = 0 With Selection.ParagraphFormat .LeftIndent = InchesToPoints(0) .RightIndent = InchesToPoints(0) .SpaceBefore = 6 .SpaceBeforeAuto = False .SpaceAfter = 6 .SpaceAfterAuto = False .LineSpacingRule = wdLineSpaceSingle .Alignment = wdAlignParagraphLeft .Hyphenation = True .FirstLineIndent = InchesToPoints(0) .OutlineLevel = wdOutlineLevelBodyText .CharacterUnitLeftIndent = 0 .CharacterUnitRightIndent = 0 .CharacterUnitFirstLineIndent = 0 .LineUnitBefore = 0 .LineUnitAfter = 0 .CollapsedByDefault = False End With With Selection.Find .Text = "^t" .Replacement.Text = "" .Forward = True .Wrap = wdFindStop .Format = False Selection.Find.Execute Replace:=wdReplaceAll Selection.MoveLeft Unit:=wdCharacter, Count:=1 .Text = "'" .Replacement.Text = "'" .Forward = True .Wrap = wdFindContinue Selection.Find.Execute Replace:=wdReplaceAll .Text = """" .Replacement.Text = """" .Forward = True .Wrap = wdFindContinue Selection.Find.Execute Replace:=wdReplaceAll .Text = """," .Replacement.Text = ",""" .Forward = True .Wrap = wdFindContinue .Format = False .MatchWildcards = False Selection.Find.Execute Replace:=wdReplaceAll .Text = "'," .Replacement.Text = ",'" .Forward = True .Wrap = wdFindContinue .Format = False Selection.Find.Execute Replace:=wdReplaceAll .Text = """." .Replacement.Text = ".""" .Forward = True .Wrap = wdFindContinue .Format = False .MatchWildcards = False Selection.Find.Execute Replace:=wdReplaceAll .Text = "'." .Replacement.Text = ".'" .Forward = True .Wrap = wdFindContinue .Format = False Selection.Find.Execute Replace:=wdReplaceAll .Text = "[^l]{1,}" .Replacement.Text = "^p" .Forward = True .Wrap = wdFindContinue .Format = False .MatchWildcards = True Selection.Find.Execute Replace:=wdReplaceAll .Text = "--" .Replacement.Text = "^+" .Forward = True .Wrap = wdFindContinue .Format = False Selection.Find.Execute Replace:=wdReplaceAll .Format = False .Forward = True .Wrap = wdFindContinue .MatchWildcards = False .Replacement.Text = "^+" .Text = " ^+" .Execute Replace:=wdReplaceAll .Text = "^+ " .Execute Replace:=wdReplaceAll .Text = "[^s]{1,}" .Replacement.Text = " " .Forward = True .Wrap = wdFindContinue .MatchWildcards = True Selection.Find.Execute Replace:=wdReplaceAll .Text = "[^13]{2,}" .Replacement.Text = "^p" .Forward = True .Wrap = wdFindContinue .MatchWildcards = True Selection.Find.Execute Replace:=wdReplaceAll .Text = "([^13] [^13]){1,}" .Replacement.Text = "^p" .Forward = True .Wrap = wdFindContinue .MatchWildcards = True Selection.Find.Execute Replace:=wdReplaceAll .Text = "[ ]{2,}" .Replacement.Text = " " .Forward = True .Wrap = wdFindContinue .MatchWildcards = True Selection.Find.Execute Replace:=wdReplaceAll End With End With End Sub |
#2
|
|||
|
|||
Possibly. What if you let this person running Word 2007 record a macro doing one of these tasks, and look at the result created in their version. You could also test your existing code by commenting out that line Word is complaining about to see if it runs without it. If you're lucky, that's the only problem.
|
#3
|
|||
|
|||
Thanks for your reply, which I passed on to the user. Here is his response. Any ideas?
I was able to get the macro to run by commenting out the following commands: NumberSpacing = … NumberForm = … StylisticSet = … ContextualAlternates = … CollapseByDefault = … For some reason my version of Word is not recognizing the syntax of these statements as valid. |
#4
|
|||
|
|||
Okay, then my next thought is to have the person using Word 2007 record a macro that does all the things you need. They may need to do one of these finds at a time, and just keep grabbing the syntax of the code that is recorded by the macro. Once you have all of that, then we can look at what was recorded and see if we can optimize that to run as a script.
|
#5
|
|||
|
|||
Is the document the macro is being run against in Compatibility Mode, or in Wd2003 format (.doc instead of .docx)?
|
Thread Tools | |
Display Modes | |
|
Similar Threads | ||||
Thread | Thread Starter | Forum | Replies | Last Post |
Compile error on hidden module | Simss | Excel Programming | 2 | 09-25-2017 01:37 AM |
compile error expected end sub | ashg75 | Word VBA | 2 | 07-13-2017 07:08 AM |
Compile error in Module | ksigcajun | Word VBA | 2 | 04-08-2015 06:44 AM |
Compile error: sub or function not defined.. | xena2305 | Excel Programming | 0 | 08-02-2011 10:17 AM |
compile error in Word | raco | Word | 0 | 09-28-2010 12:40 PM |