Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Opeining a Word Doc based on Screen name

Status
Not open for further replies.

Losman500

Technical User
Oct 9, 2007
43
US
Hi, I'm currently using Extra! Extreme and I've also written several macros to populate fields in Excel/Word; however I think this is over my head. I need to create a macro that when executed will read the screen name and based on that name open a specific word document. This is sort of a help macro that will open a file that describes what the screen does. I think I would need to use an Array but I'm not quite sure how to go about writing it it.
We currently have about 300 screens and growing, all of which would open a separate Word document.

Any suggestions?
 
You need to scrape the screen name and then use a Select Case statement. Physedo code below

Select case Myscreen.Getstring(x,y,l)
case is=Screen 1
open doc for screen 1
case is=Screen 2
open doc screen 2
......
 
Thanks for the help you put me on the right track, however I think I'm having problems with the Open statement. When I run my macro nothing opens but I get no errors either.
My Code:
Code:
Sub Main
    Dim Sys as Object, Sess As Object
    
    Set Sys = CreateObject("Extra.System")
    
    If Sys is Nothing then
        MsgBox ("Could not create Extra!.System...is E!PC installed in this machine?")
        Exit Sub
    End If
    
    Set Sess = Sys.ActiveSession
    
    If Sess Is Nothing then 
        MsgBox ("No Session Available...Stopping Macro playback.")
        Exit Sub
    End If
    
    Select case Sess.Screen.Getstring(1,2,4)
        Case is=FOHM
        open "V:\FOHM.doc" for Output As # 1
        Case is=FDQQ
        open "V:\FDQQ.doc" for Output As # 2
    End Select   
End Sub
 
Code:
Set objApp = CreateObject("Word.Application.8")
Set objDoc = objApp.Documents.Open("V:\FOHM.doc")
objApp.Visible = True
objApp.WindowState = 1]
 
Great thanks, this is just what I needed it. I have one more question I would like to return a MsgBox if the name of screen is not listed in the cases. I think if I put this as my last case, it should check all my cases and if non of them trigger to open a file then it would issue a msgbox
This seems to work on my code, but is this the best way?


Code:
Select case Sess.Screen.Getstring(1,2,4) 
           
        Case is = "FOHM"
        Set objDoc = objApp.Documents.Open("V:\FOHM.doc")
        objApp.Visible = True
        Case is = "FDQQ"
        Set objDoc = objApp.Documents.Open("V:\FDQQ.doc")
        objApp.Visible = True
        Case is = "ARTI"
        Set objDoc = objApp.Documents.Open("V:\ARTI.doc")
        objApp.Visible = True
        Case is = "DISM"
        Set objDoc = objApp.Documents.Open("V:\DISM.doc")
        objApp.Visible = True
        Case is = "FCAL"
        Set objDoc =  objApp.Documents.Open("V:\FCAL.doc")
        objApp.Visible = True
        
        Case is <> "FOHM"
        msgbox ("No Help File Available")
 
Actually, the last entry of a 'select case' statement should be 'case else'. This would then display the message box.
 
I thought so, even though this way seem to work as well the proper way is with Case Else.

Thank You very much
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top