Maliki Hassani
asked on
VBA to VB Script - Code modify
Hello Experts,
First off, I am new to VBScript so please bare with me. I have a VBA script in MS Word, that I need to have it recoded to work in a VB script. I was wondering if someone could help me out. Here are the 4 scripts:
Below is the VBScript that I am working with. Notice I added a section for insert VBA code.
Since I am only bolding specific text.. Perhasps I should simplify this and write it in VB Script?
Thanks
First off, I am new to VBScript so please bare with me. I have a VBA script in MS Word, that I need to have it recoded to work in a VB script. I was wondering if someone could help me out. Here are the 4 scripts:
Option Explicit
Sub SetBold()
Const Mark As String = "BHN-"
Dim Rng As Range
Dim Rstart As Long, Rend As Long
Dim Fnd As Boolean
Rstart = 1
Do
Rstart = GetStart(Mark, ActiveDocument.Range(Rstart), Rstart)
If Rstart = 0 Then Exit Do
Set Rng = ActiveDocument.Range(Start:=Rstart + Len(Mark) + 1)
Rend = GetStart(") -", Rng, Rstart + Len(Mark) + 1)
Fnd = CBool(Rend)
If Rend = 0 Then Rend = Rstart + Len(Mark) - 1
Set Rng = ActiveDocument.Range(Start:=Rstart, End:=Rend)
Rng.Bold = True
Rstart = Rend + 1
Loop While Fnd
End Sub
Sub SetRestBold()
Const Mark As String = "Score:"
Dim Rng As Range
Dim Rstart As Long, Rend As Long
Dim Fnd As Boolean
Rstart = 1
Do
Rstart = GetStart(Mark, ActiveDocument.Range(Rstart), Rstart)
If Rstart = 0 Then Exit Do
Set Rng = ActiveDocument.Range(Start:=Rstart + Len(Mark) + 1)
Rend = GetStart(" - ", Rng, Rstart + Len(Mark) + 1)
Fnd = CBool(Rend)
If Rend = 0 Then Rend = Rstart + Len(Mark) - 1
Set Rng = ActiveDocument.Range(Start:=Rstart, End:=Rend)
Rng.Bold = True
Rstart = Rend + 1
Loop While Fnd
End Sub
Sub SetBoldLevel6()
Const Mark As String = "LEVEL 6 Events:"
Dim Rng As Range
Dim Rstart As Long, Rend As Long
Dim Fnd As Boolean
Rstart = 1
Do
Rstart = GetStart(Mark, ActiveDocument.Range(Rstart), Rstart)
If Rstart = 0 Then Exit Do
Set Rng = ActiveDocument.Range(Start:=Rstart + Len(Mark) + 1)
Rend = GetStart("LEVEL 6 Events:", Rng, Rstart + Len(Mark) + 1)
Fnd = CBool(Rend)
If Rend = 0 Then Rend = Rstart + Len(Mark) - 1
Set Rng = ActiveDocument.Range(Start:=Rstart, End:=Rend)
Rng.Bold = True
Rstart = Rend + 1
Loop While Fnd
End Sub
Sub SetBoldLevel5()
Const Mark As String = "LEVEL 5 Events:"
Dim Rng As Range
Dim Rstart As Long, Rend As Long
Dim Fnd As Boolean
Rstart = 1
Do
Rstart = GetStart(Mark, ActiveDocument.Range(Rstart), Rstart)
If Rstart = 0 Then Exit Do
Set Rng = ActiveDocument.Range(Start:=Rstart + Len(Mark) + 1)
Rend = GetStart("LEVEL 5 Events:", Rng, Rstart + Len(Mark) + 1)
Fnd = CBool(Rend)
If Rend = 0 Then Rend = Rstart + Len(Mark) - 1
Set Rng = ActiveDocument.Range(Start:=Rstart, End:=Rend)
Rng.Bold = True
Rstart = Rend + 1
Loop While Fnd
End Sub
Below is the VBScript that I am working with. Notice I added a section for insert VBA code.
'Language = VBScript
'Script to process, format, and email the Weekly Event Doc
Sub FormatReport
Set objWord = CreateObject("Word.Application")
Set objDoc = objWord.Documents.Open("C:\Documents and Settings\lspaz\Desktop\Test Report Automation\XXX.docx")
***INSERT VBA CODE
objWord.Quit
Since I am only bolding specific text.. Perhasps I should simplify this and write it in VB Script?
Thanks
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
That is brilliant! I was having such a hard time Thank you so much.. It works, I will let you know if I have any questions though!
ASKER
Thank you!
Chris