ExcelBanter

ExcelBanter (https://www.excelbanter.com/)
-   Excel Programming (https://www.excelbanter.com/excel-programming/)
-   -   Can I change this to work for a closed workbook (https://www.excelbanter.com/excel-programming/335255-can-i-change-work-closed-workbook.html)

Shawn

Can I change this to work for a closed workbook
 
Below is my code which works fine. However, it requires the "Employee
Database.xls" file to already be open. How could I change my code so that it
is pulling this data from a closed "Employee Database.xls" file?

Sub UpdateCodeBook()
'
' Employees Macro
' Macro recorded 9/28/2004 by Shawn D. Crabtree
'
' Keyboard Shortcut: Ctrl+Shift+E


Sheets("Names").Columns("A:C").ClearContents
Windows("Employee Database.xls").Activate
Sheets("Library").Range("C:C,E:E,BE:BE").Copy
ActiveWindow.ActivateNext
Sheets("Names").Select
Range("A1").PasteSpecial Paste:=xlValues, Operation:=xlNone,
SkipBlanks:= _
False, Transpose:=False
Application.DisplayAlerts = False
Windows("Employee DataBase.xls").Close
Application.DisplayAlerts = True
Sheets("Names").Select
Range("A1").Select
End Sub



--
Thanks
Shawn

CDICKENS

Can I change this to work for a closed workbook
 
You can try saving "Employee Database.xls" as an addin. Then load the
file as an addin. Whenever you open excel the Employee Database will
be open.

A couple of Caveots...

You will need to code a Workbook.Save action in the workbook before
close event of the Employee Database.

Also if multiple users will be working in this file at the same time,
you may need to look into using MS Access instead of excel.

Thanks,
Chuck

Shawn wrote:
Below is my code which works fine. However, it requires the "Employee
Database.xls" file to already be open. How could I change my code so that it
is pulling this data from a closed "Employee Database.xls" file?

Sub UpdateCodeBook()
'
' Employees Macro
' Macro recorded 9/28/2004 by Shawn D. Crabtree
'
' Keyboard Shortcut: Ctrl+Shift+E


Sheets("Names").Columns("A:C").ClearContents
Windows("Employee Database.xls").Activate
Sheets("Library").Range("C:C,E:E,BE:BE").Copy
ActiveWindow.ActivateNext
Sheets("Names").Select
Range("A1").PasteSpecial Paste:=xlValues, Operation:=xlNone,
SkipBlanks:= _
False, Transpose:=False
Application.DisplayAlerts = False
Windows("Employee DataBase.xls").Close
Application.DisplayAlerts = True
Sheets("Names").Select
Range("A1").Select
End Sub



--
Thanks
Shawn




All times are GMT +1. The time now is 11:13 AM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
ExcelBanter.com