PDA

View Full Version : VBA code to search XPS document



rugbykorn
03-28-2013, 01:38 PM
Hello,

I am working on a project in which I will search for a string in an XPS document (string example: "Employee Name:"), and then based on its location I will reference the 15 characters to the right of the string (this will be the employee's name). I will then save the document with the Employee's Name as part of the file name.

The code I have so far is:



Sub Button1_Click()


Dim ie As Object
Dim ToFind As String
Set ie = CreateObject("InternetExplorer.Application")
ie.Visible = True
ie.Navigate "C:\Documents and Settings\joseph.korn\Desktop\testxps.xps"


Do Until ie.ReadyState = READYSTATE_COMPLETE
DoEvents
Loop



ToFind = "test"
findtext = InStr(1, innertext, ToFind)



MsgBox findtext


Set ie = Nothing
End Sub


This will open Internet Explorer and then navigate to the file on my desktop. I can't seem to figure out what needs to go in the inStr function in place of "innertext" as that doesn't seem to be working. Any help would be greatly appreciated. I think what I need is to know how to reference the now open XPS document, I will need that to then save the file with a new name but right now I am just concerned with getting the search working.

Thanks for taking the time to read this.

RugbyKorn