Microsoft Office Forums

Go Back   Microsoft Office Forums > >

Reply
 
Thread Tools Display Modes
  #1  
Old 03-28-2016, 08:02 PM
rpb925 rpb925 is offline Calling Sub Routine for Formatting recently Created Word Document Windows 7 64bit Calling Sub Routine for Formatting recently Created Word Document Office 2010 64bit
Novice
Calling Sub Routine for Formatting recently Created Word Document
 
Join Date: Mar 2016
Location: Sydney
Posts: 17
rpb925 is on a distinguished road
Default

Greg,

That is mind boggling. It's so concise. Thanks heaps The eyes bleeding was a good burn by the way. So the code works perfectly when I run as a normal macro in a word document but when I try and call it from my vba in access for a nearly created word document its not working so I don't believe I am calling it correctly or it isn't being referenced. I have saved the script in a module. Then I call the sub routine. The script runs but nothing happens. So I think it is the following line that might not be referencing the document correctly as I am not in the document as such it has just been created and is being filled with text using VBA. Is there any other way to reference the newly created word document.
Your reference
Code:
Set oRng = ActiveDocument.Range
In the father routine it is referenced as follows
Code:
'Create a new document
    Set wdDoc = .Documents.Add
    With wdDoc
Can I use the reference wdDoc or can I not use the reference from the father routine in the child sub routine?



Thanks.
Reply With Quote
  #2  
Old 03-28-2016, 09:00 PM
macropod's Avatar
macropod macropod is offline Calling Sub Routine for Formatting recently Created Word Document Windows 7 64bit Calling Sub Routine for Formatting recently Created Word Document Office 2010 32bit
Administrator
 
Join Date: Dec 2010
Location: Canberra, Australia
Posts: 22,375
macropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond repute
Default

Quote:
Originally Posted by rpb925 View Post
That is mind boggling. It's so concise.
Nah, it's verbose! Consider:
Code:
Sub Demo()
Dim arrTerms(), i As Long
arrTerms = Array("italics", "bold", "indent")
With ActiveDocument.Range.Find
    .MatchWildcards = True
    .Replacement.Text = "\3"
    For i = 0 To UBound(arrTerms)
        .Replacement.ClearFormatting
        .Text = "(\<" & arrTerms(i) & ")(\>)(*)\1/\2"
        Select Case i
            Case 0: .Replacement.Font.Italic = True
            Case 1: .Replacement.Font.Bold = True
            Case 2: .Replacement.ParagraphFormat.LeftIndent = 72
        End Select
        .Execute Replace:=wdReplaceAll
    Next
End With
End Sub
__________________
Cheers,
Paul Edstein
[Fmr MS MVP - Word]
Reply With Quote
Reply



Similar Threads
Thread Thread Starter Forum Replies Last Post
Adding tables to Created word document whilst other word document open Help rpb925 Word VBA 18 03-30-2016 04:45 PM
Calling Sub Routine for Formatting recently Created Word Document Uploading a previously created bibliography to be used in a new document JennJenn79 Word 1 07-16-2015 09:34 PM
Calling Sub Routine for Formatting recently Created Word Document was document created using 2010 or 2013 TDOG Word 1 10-12-2014 03:37 PM
Copy format created by a conditional formatting spk Excel 2 04-10-2013 04:41 AM
Word crashing on "sort" routine Kayale Word 0 04-12-2010 04:54 PM

Other Forums: Access Forums

All times are GMT -7. The time now is 05:34 PM.


Powered by vBulletin® Version 3.8.11
Copyright ©2000 - 2025, vBulletin Solutions Inc.
Search Engine Optimisation provided by DragonByte SEO (Lite) - vBulletin Mods & Addons Copyright © 2025 DragonByte Technologies Ltd.
MSOfficeForums.com is not affiliated with Microsoft