View Single Post
  #2   Report Post  
Posted to microsoft.public.excel.programming
Gary Keramidas Gary Keramidas is offline
external usenet poster
 
Posts: 2,494
Default Get info from a file that is already open

not sure what you're looking for. you can try opening the file as read only to
and see if that helps.

Workbooks.Open sFilePath, ReadOnly:=True

--


Gary


"ricowyder" wrote in message
oups.com...
Dear users,

I have the following macro, which is working fine (surely, there can
be improvement):

Private Sub CommandButtonUpdate_Click()

Dim i As Integer
Dim j As Integer
Dim idString As String
Dim sFilePath As String
Dim NameStaff As String
Dim wbNew As Workbook
Dim wb As Workbook
Set wb = ActiveWorkbook

Application.ScreenUpdating = False

For i = 1 To 32

j = i + 7
idString = ActiveSheet.Range("C" & j).Text
If idString < "" Then
sFilePath = "L:\Year Planner\PresenceCheck\users\" & idString
Application.DisplayAlerts = False
Workbooks.Open sFilePath
Set wbNew = ActiveWorkbook
wb.Sheets(1).Range("D" & j).Value =
wbNew.Sheets(1).Range("D9").Value
wb.Sheets(1).Range("E" & j).Value =
wbNew.Sheets(1).Range("D20").Value
wbNew.Close
End If
Next

Application.ScreenUpdating = True
Application.DisplayAlerts = True
End Sub

My problem: the purpose of this macro is to go into each staffs own
Excel file (all saved on server) to get the info

wb.Sheets(1).Range("D" & j).Value =
wbNew.Sheets(1).Range("D9").Value
wb.Sheets(1).Range("E" & j).Value =
wbNew.Sheets(1).Range("D20").Value

However, our staff has opened these files all the time. As soon as a
file is already opened, the update does not work anymore.
How can I avoid this problem (I guess it is read-only). PLEASE HELP!

Thanks a lot.

Regards,

Rico