Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 389
Default Get cell value from other workbook

I am using: Question is below the code:

Dim Wkbk As Workbook
Dim myFileName As String
Dim myPath As String

myPath = "C:\ThisDirectory\" '<- include that backslash!
myFileName = "File001.xls"

Set Wkbk = Nothing
On Error Resume Next
Set Wkbk = Workbooks(myFileName)
On Error GoTo 0

If Wkbk Is Nothing Then
'it's not open
Set Wkbk = Workbooks.Open(Filename:=myPath & myFileName, _
UpdateLinks:=False, ReadOnly:=False, Password:="aoaoao")
Wkbk.RunAutoMacros which:=xlAutoOpen
If Wkbk.HasPassword = False Then
Wkbk.Close savechanges:=False
MsgBox "Error occured in opening the file."
End If
Else
MsgBox "The file is already open!"
End If

My question is: Is there a way to get the value of cell "L1" form the Wkbk.
And also is there a way to change the value of cell "L1" in the Wkbk. And
do this within the flow of the macro. I would really like to do it using the
Workbook "Wkbk" method. If not possible, what is the method to do this?

Thank you,

Steven
  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 35,218
Default Get cell value from other workbook

Suppose L1 is on a worksheet named Sheet1:

Dim Wkbk As Workbook
Dim myFileName As String
Dim myPath As String

myPath = "C:\ThisDirectory\" '<- include that backslash!
myFileName = "File001.xls"

Set Wkbk = Nothing
On Error Resume Next
Set Wkbk = Workbooks(myFileName)
On Error GoTo 0

If Wkbk Is Nothing Then
'it's not open
Set Wkbk = Workbooks.Open(Filename:=myPath & myFileName, _
UpdateLinks:=False, ReadOnly:=False, Password:="aoaoao")
Wkbk.RunAutoMacros which:=xlAutoOpen

'do you want to retrieve the value after the auto_open procedure runs?
'do you want to put that value in a cell in the workbook that holds the
'code?
thisworkbook.worksheets("sheet9999").range("a1").v alue _
= wkbk.worksheets("sheet1").range("L1").value

wkbk.worksheets("sheet1").range("l1").value = "someothervaluehere"

'but after changing the value, I would think you'd want to
'save the changed workbook.
If Wkbk.HasPassword = False Then
Wkbk.Close savechanges:=False
MsgBox "Error occured in opening the file."
End If
Else
MsgBox "The file is already open!"
End If

Steven wrote:

I am using: Question is below the code:

Dim Wkbk As Workbook
Dim myFileName As String
Dim myPath As String

myPath = "C:\ThisDirectory\" '<- include that backslash!
myFileName = "File001.xls"

Set Wkbk = Nothing
On Error Resume Next
Set Wkbk = Workbooks(myFileName)
On Error GoTo 0

If Wkbk Is Nothing Then
'it's not open
Set Wkbk = Workbooks.Open(Filename:=myPath & myFileName, _
UpdateLinks:=False, ReadOnly:=False, Password:="aoaoao")
Wkbk.RunAutoMacros which:=xlAutoOpen
If Wkbk.HasPassword = False Then
Wkbk.Close savechanges:=False
MsgBox "Error occured in opening the file."
End If
Else
MsgBox "The file is already open!"
End If

My question is: Is there a way to get the value of cell "L1" form the Wkbk.
And also is there a way to change the value of cell "L1" in the Wkbk. And
do this within the flow of the macro. I would really like to do it using the
Workbook "Wkbk" method. If not possible, what is the method to do this?

Thank you,

Steven


--

Dave Peterson
  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 389
Default Get cell value from other workbook

Dave,

Thank you for answering both my question. You gave me the Wkbk earlier and
now this. This is such incredibly valuable knowledge and you answer it with
such ease. There should be a user group conference where all the users chip
in and we award something very nice to you and Tom Ogilvy. There may be some
other gurus, but I cant think of them right now.

Thank you so much for your help.

Steven

"Dave Peterson" wrote:

Suppose L1 is on a worksheet named Sheet1:

Dim Wkbk As Workbook
Dim myFileName As String
Dim myPath As String

myPath = "C:\ThisDirectory\" '<- include that backslash!
myFileName = "File001.xls"

Set Wkbk = Nothing
On Error Resume Next
Set Wkbk = Workbooks(myFileName)
On Error GoTo 0

If Wkbk Is Nothing Then
'it's not open
Set Wkbk = Workbooks.Open(Filename:=myPath & myFileName, _
UpdateLinks:=False, ReadOnly:=False, Password:="aoaoao")
Wkbk.RunAutoMacros which:=xlAutoOpen

'do you want to retrieve the value after the auto_open procedure runs?
'do you want to put that value in a cell in the workbook that holds the
'code?
thisworkbook.worksheets("sheet9999").range("a1").v alue _
= wkbk.worksheets("sheet1").range("L1").value

wkbk.worksheets("sheet1").range("l1").value = "someothervaluehere"

'but after changing the value, I would think you'd want to
'save the changed workbook.
If Wkbk.HasPassword = False Then
Wkbk.Close savechanges:=False
MsgBox "Error occured in opening the file."
End If
Else
MsgBox "The file is already open!"
End If

Steven wrote:

I am using: Question is below the code:

Dim Wkbk As Workbook
Dim myFileName As String
Dim myPath As String

myPath = "C:\ThisDirectory\" '<- include that backslash!
myFileName = "File001.xls"

Set Wkbk = Nothing
On Error Resume Next
Set Wkbk = Workbooks(myFileName)
On Error GoTo 0

If Wkbk Is Nothing Then
'it's not open
Set Wkbk = Workbooks.Open(Filename:=myPath & myFileName, _
UpdateLinks:=False, ReadOnly:=False, Password:="aoaoao")
Wkbk.RunAutoMacros which:=xlAutoOpen
If Wkbk.HasPassword = False Then
Wkbk.Close savechanges:=False
MsgBox "Error occured in opening the file."
End If
Else
MsgBox "The file is already open!"
End If

My question is: Is there a way to get the value of cell "L1" form the Wkbk.
And also is there a way to change the value of cell "L1" in the Wkbk. And
do this within the flow of the macro. I would really like to do it using the
Workbook "Wkbk" method. If not possible, what is the method to do this?

Thank you,

Steven


--

Dave Peterson

  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 35,218
Default Get cell value from other workbook

You hang around the newsgroups for a little bit (just lurking if you want) and
you'll see that these newsgroups are filled with helpful people.

But thanks for the kind words.

Steven wrote:

Dave,

Thank you for answering both my question. You gave me the Wkbk earlier and
now this. This is such incredibly valuable knowledge and you answer it with
such ease. There should be a user group conference where all the users chip
in and we award something very nice to you and Tom Ogilvy. There may be some
other gurus, but I cant think of them right now.

Thank you so much for your help.

Steven

"Dave Peterson" wrote:

Suppose L1 is on a worksheet named Sheet1:

Dim Wkbk As Workbook
Dim myFileName As String
Dim myPath As String

myPath = "C:\ThisDirectory\" '<- include that backslash!
myFileName = "File001.xls"

Set Wkbk = Nothing
On Error Resume Next
Set Wkbk = Workbooks(myFileName)
On Error GoTo 0

If Wkbk Is Nothing Then
'it's not open
Set Wkbk = Workbooks.Open(Filename:=myPath & myFileName, _
UpdateLinks:=False, ReadOnly:=False, Password:="aoaoao")
Wkbk.RunAutoMacros which:=xlAutoOpen

'do you want to retrieve the value after the auto_open procedure runs?
'do you want to put that value in a cell in the workbook that holds the
'code?
thisworkbook.worksheets("sheet9999").range("a1").v alue _
= wkbk.worksheets("sheet1").range("L1").value

wkbk.worksheets("sheet1").range("l1").value = "someothervaluehere"

'but after changing the value, I would think you'd want to
'save the changed workbook.
If Wkbk.HasPassword = False Then
Wkbk.Close savechanges:=False
MsgBox "Error occured in opening the file."
End If
Else
MsgBox "The file is already open!"
End If

Steven wrote:

I am using: Question is below the code:

Dim Wkbk As Workbook
Dim myFileName As String
Dim myPath As String

myPath = "C:\ThisDirectory\" '<- include that backslash!
myFileName = "File001.xls"

Set Wkbk = Nothing
On Error Resume Next
Set Wkbk = Workbooks(myFileName)
On Error GoTo 0

If Wkbk Is Nothing Then
'it's not open
Set Wkbk = Workbooks.Open(Filename:=myPath & myFileName, _
UpdateLinks:=False, ReadOnly:=False, Password:="aoaoao")
Wkbk.RunAutoMacros which:=xlAutoOpen
If Wkbk.HasPassword = False Then
Wkbk.Close savechanges:=False
MsgBox "Error occured in opening the file."
End If
Else
MsgBox "The file is already open!"
End If

My question is: Is there a way to get the value of cell "L1" form the Wkbk.
And also is there a way to change the value of cell "L1" in the Wkbk. And
do this within the flow of the macro. I would really like to do it using the
Workbook "Wkbk" method. If not possible, what is the method to do this?

Thank you,

Steven


--

Dave Peterson


--

Dave Peterson
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
linked workbook cell returns 0 is source workbook cell is blank? Syd[_2_] Excel Worksheet Functions 4 April 13th 09 07:49 PM
Refresh pivot table in workbook A when changing a cell in workbook gildengorin Excel Worksheet Functions 2 March 17th 09 04:59 PM
Find cell in Excel2000 workbook with link from another workbook? Mark4mmx Excel Discussion (Misc queries) 1 October 8th 08 12:55 PM
automatically move cell data in 1 workbook to another workbook Genesis Excel Worksheet Functions 1 November 5th 06 07:35 PM


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

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

About Us

"It's about Microsoft Excel"