Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1
Default Declaring a variable?

I have this code which when a cell is selected loads up a certain wor
file. All the word files are stored in the same folder. Currently, whe
a cell is selected an option is shown which asks the user if they wan
to view the word file for that cell. The problem I have is that whe
Yes is selected, the code doesn't load up the word file I want, i
wants to load up the document named 'Target'. Do I have to declare thi
'Target' a variable. Very confused, any help would be great. The code
have is below:

Private Sub Worksheet_SelectionChange(ByVal Target As Range)

Dim intResponse As Integer
Dim WrdApp As Object
Set WrdApp = CreateObject("Word.Application")

' Determines whether the cell has a BOM# within it
If Left(Target, 3) = "BOM" Then

' Displays a message box allow with options
intResponse = MsgBox("Would you like to open " & Target & " ?"
vbYesNo)

' Selects the outcome if Yes is chosen
If intResponse = vbYes Then

' Opens word file
With WrdApp
.Documents.Open Filename:="S:\Technical\Target"
ReadOnly:=True
End With

WrdApp.Visible = True

End If



End I

--
Message posted from http://www.ExcelForum.com

  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 111
Default Declaring a variable?

"S:\Technical\Target",
is a string and every character is read *as*
a character, so Excel will have no way of
recognizing "Target" as the variable Target.
instead use:

Documents.Open Filename:="S:\Technical\" & Target.Value


--
Best Regards
Leo Heuser

Followup to newsgroup only please.

"pgoodale" skrev i en meddelelse
...
I have this code which when a cell is selected loads up a certain word
file. All the word files are stored in the same folder. Currently, when
a cell is selected an option is shown which asks the user if they want
to view the word file for that cell. The problem I have is that when
Yes is selected, the code doesn't load up the word file I want, it
wants to load up the document named 'Target'. Do I have to declare this
'Target' a variable. Very confused, any help would be great. The code I
have is below:

Private Sub Worksheet_SelectionChange(ByVal Target As Range)

Dim intResponse As Integer
Dim WrdApp As Object
Set WrdApp = CreateObject("Word.Application")

' Determines whether the cell has a BOM# within it
If Left(Target, 3) = "BOM" Then

' Displays a message box allow with options
intResponse = MsgBox("Would you like to open " & Target & " ?",
vbYesNo)

' Selects the outcome if Yes is chosen
If intResponse = vbYes Then

' Opens word file
With WrdApp
Documents.Open Filename:="S:\Technical\Target",
ReadOnly:=True
End With

WrdApp.Visible = True

End If



End If


---
Message posted from http://www.ExcelForum.com/



  #3   Report Post  
Posted to microsoft.public.excel.programming
jj jj is offline
external usenet poster
 
Posts: 2
Default Declaring a variable?

I think that's because that's precisely what these lines:

With WrdApp
.Documents.Open Filename:="S:\Technical\Target",
ReadOnly:=True
End With


tell it to do :-)

Looks like you've forgotten to concatenate something onto the end of
the filename string, presumably a value derived from the cell you've
just clicked on. Plus I'd expect that filename to end in .doc as it's
a word file.

HTH,
John
Reply
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
Declaring variables freekrill Excel Discussion (Misc queries) 2 July 19th 06 06:36 AM
Declaring variables freekrill Excel Discussion (Misc queries) 0 July 18th 06 06:15 PM
Declaring Variables Robert[_16_] Excel Programming 2 November 20th 03 04:16 PM
Declaring variables Pedro Excel Programming 1 November 13th 03 03:32 PM
Declaring Variables chris brunt Excel Programming 2 August 4th 03 02:02 PM


All times are GMT +1. The time now is 01:02 PM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
Copyright ©2004-2025 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"