Hello and thanks in advance!
Running Excel 2013 on Windows 7.
I have a formula where I'm trying to fill bookmarks in a Word Document. I'm trying to get it to check if I1 = certain text, then goto Line1 else goto Line2 and so on. But, even though I1 in my sheet DOES = "Humanities", my code is skipping to Line4 and giving me the msgbox
Here is my code
If anybody could tell me WHY this is happening that would be great.
Is it because I used a macro to get Humanities to appear in I1, if so, how can I get around this?
Running Excel 2013 on Windows 7.
I have a formula where I'm trying to fill bookmarks in a Word Document. I'm trying to get it to check if I1 = certain text, then goto Line1 else goto Line2 and so on. But, even though I1 in my sheet DOES = "Humanities", my code is skipping to Line4 and giving me the msgbox
Here is my code
Code:
Sub RunThisOne()
Dim objWord As Object
Dim ws As Worksheet
Dim headerstring As String
Set ws = ThisWorkbook.Sheets("EnglishCreativeWr")
Set objWord = CreateObject("Word.Application")
objWord.Visible = True
objWord.Documents.Open "C:\Users\thomassa\Desktop\thistemplate.dotm" ' change as required
With objWord.ActiveDocument
.Bookmarks("EKU_Major").Range.Text = ws.Name
If ("I1") = "Heritage" Then GoTo Line1 Else GoTo Line2
Line1:
.Bookmarks("Heritage_Class1").Range.Text = ws.Range("I6").Value
.Bookmarks("Heritage_Class2").Range.Text = ws.Range("I7").Value
.Bookmarks("Heritage_Class3").Range.Text = ws.Range("I8").Value
Line2:
If ("I1") = "Humanities" Then GoTo Line3 Else GoTo Line4
Line3:
.Bookmarks("Humanities_Class1").Range.Text = ws.Range("I6").Value
Line4:
MsgBox "Doesn't exist, sorry"
End With
Set objWord = Nothing
End Sub
If anybody could tell me WHY this is happening that would be great.
Is it because I used a macro to get Humanities to appear in I1, if so, how can I get around this?