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 IamaSherpa on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Need to open word document from excel.

Status
Not open for further replies.

Galanthus

Technical User
Oct 21, 2003
5
GB
I need to open a word document from excel when a specific date is entered. I'm sure this is relatively simple I'm just no good with excel and would appreciate any pointers.
 
It is easy to put a hyperlink in the worksheet to the Word file, and have it active if a certain date is entered, with this formula:
=IF(C5=DATE(2005,6,21),HYPERLINK("C:\Documents and Settings\bchambers\My Documents\AboutDraper.doc","ClICK HERE"),""), but it won't open the document automatically. That will probably require a macro.

Sawedoff

 
The following will open a file in Word and make it visible
Code:
Private Sub Workbook_SheetChange(ByVal Sh As Object, ByVal Target As Range)
If (Range("A1").Value = "21/06/2005") Then
    Set objwordapp = CreateObject("Word.Application")
        
        objwordapp.documents.Open Filename:="H:\SW1.doc"
        objwordapp.Visible = True
    Set objwordapp = Nothing
    
End If
End Sub

Range "A1" in this case is where you'd put the date, and you'd have to change the date to match your requirements. Also change the filename (obviously).

This should be placed in the VBA Editor (Press Alt-F11) and into the ThisWorkbook module.


Cheers,
Dave

Probably the only Test Analyst Manager on Tek-Tips...therefore whatever it was that went wrong, I'm to blame...

animadverto vos in Abyssus!

Take a look at Forum1393!
 
Thanks both of you for the solutions to my problem. I opted for DPlank's solution. Can I just ask how do I adjust the script for it to be triggered by one of two different dates. Thanks for your help scripts are as you've probably guessed not my strong point.

Cheers.
 
Code:
If (Range("A1").Value = "firstDate") [red] Or (Range("A1").Value = "secondDate")[/red] Then

replace firstDate and secondDate with the values you want to use.

Cheers,
Dave

Probably the only Test Analyst Manager on Tek-Tips...therefore whatever it was that went wrong, I'm to blame...

animadverto vos in Abyssus!

Take a look at Forum1393!
 
Thanks,

That works fine now. Much appreciated.

Regards,

Dan.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top