PDA

View Full Version : Not Cross-Posted VBA Question



IcePirate
03-04-2009, 11:45 AM
Hello, this topic, related to my thread here
http://www.vbaexpress.com/forum/showthread.php?p=177567

I have ensured this topic is not cross posted, and if I do place this question on other forums Ill post links here.

I have a simple Macro (see below) Im trying to create two instances of this Macro one to fill in the first_mark book mark, and the second to fill in the second_mark book mark, (but all in one Macro)...I tried using IF, and With to separate the statements, but Im getting nothing but errors, was hoping someone could help out.

Sub AutoOpen()
Dim myWB As Excel.Workbook
Dim TempStr As String
Set myWB = GetObject("C:\PROJECT\excel.xls")
Selection.GoTo What:=wdGoToBookmark, Name:="first_mark"
Selection.TypeText (CStr(myWB.Sheets("PayHist").Range("A" & 1)))
Set myWB = Nothing

With myWB
Selection.GoTo What:=wdGoToBookmark, Name:="SECOND_mark"
Selection.TypeText (CStr(myWB.Sheets("PayHist").Range("A" & 1)))
End With

End Sub

fumei
03-04-2009, 12:09 PM
Please read the FAQ on getting help from these forums.

"but Im getting nothing but errors, was hoping someone could help out."

When ever you mention errors, please state what the error is. The rror number if you have it, but more importantly, what is the text of the error message.

We are not mind readers, and we can not see what you see on your screen.

Errors? WHAT errors? Is it an error because the bookmark does not exist? Who knows? Is it an error because the code can not get the value you are trying to get?

I suspect so, as you have not set an instance of Excel!!!.

Dim myWB As Excel.Workbook
Dim TempStr As String
Set myWB = GetObject("C:\PROJECT\excel.xls")

this is wrong wrong wrong. You should be getting an error on the Set myWB line...but who knows, as you do not say.