Logo 
Search:

MS Office Answers

Ask Question   UnAnswered
Home » Forum » MS Office       RSS Feeds
  Question Asked By: Almas Akhtar   on Feb 26 In MS Office Category.

  
Question Answered By: Gilberto Thompson   on Feb 26

Here are some examples of accessing a workbook as a hidden object:

Sub Copy2()
'Open Book2.xls as hidden object and copy
'some data  from it to Book1.xls
twp = ThisWorkbook.Path
Set Wb1 = GetObject(twp & "\Book1.xls")
Set Wb2 = GetObject(twp & "\Book2.xls")
Wb1.Sheets("Sheet1").Range("A4:B14").Formula _
= Wb2.Sheets("Sheet1").Range("A4:B14").Formula
Wb2.Close
Set Wb1 = Nothing
Set Wb2 = Nothing
End Sub

Sub Modify2()
'Modify Book2.xls and save it
twp = ThisWorkbook.Path
Set Wb2 = GetObject(twp & "\Book2.xls")
Wb2.Sheets("Sheet1").Range("count").Value _
= Wb2.Sheets("Sheet1").Range("count").Value + 1
'Make the hidden workbook visible before saving
'else it won't be visible when opened later!
Wb2.Windows("Book2.xls").Visible = True
Wb2.Save
Wb2.Close
Set Wb2 = Nothing
End Sub

Share: 

 

This Question has 1 more answer(s). View Complete Question Thread

 
Didn't find what you were looking for? Find more on Need help Or get search suggestion and latest updates.


Tagged: