Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 134
Default Run Code in Another Workbook

Looking for automation code to have in a "Template" Workbook
that will run code in an Excel File received from Management.

This code would make a DBF from the Excel File received from Management.

TIA - Bob
  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 523
Default Run Code in Another Workbook

The following looks for an open workbook called test.xls, finds a sheet
called "Sheet1" in it and colours cell A1 light blue. It can be placed in any
other workbook & will still work:

Sub demo()

dim wb as workbook
set wb = workbooks("test.xls")

dim ws as worksheet
set ws = wb.worksheets("Sheet1")

ws.range("A1").interior.colorindex = 37

end sub

You can use activeworkbook etc rather than setting wb to a pre-named
workbook etc.

Sam


"Bob Barnes" wrote:

Looking for automation code to have in a "Template" Workbook
that will run code in an Excel File received from Management.

This code would make a DBF from the Excel File received from Management.

TIA - Bob

  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 134
Default Run Code in Another Workbook

Sam - this helps. Thank you - Bob

"Sam Wilson" wrote:

The following looks for an open workbook called test.xls, finds a sheet
called "Sheet1" in it and colours cell A1 light blue. It can be placed in any
other workbook & will still work:

Sub demo()

dim wb as workbook
set wb = workbooks("test.xls")

dim ws as worksheet
set ws = wb.worksheets("Sheet1")

ws.range("A1").interior.colorindex = 37

end sub

You can use activeworkbook etc rather than setting wb to a pre-named
workbook etc.

Sam


"Bob Barnes" wrote:

Looking for automation code to have in a "Template" Workbook
that will run code in an Excel File received from Management.

This code would make a DBF from the Excel File received from Management.

TIA - Bob

  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1
Default Run Code in Another Workbook


Is it sufficient to save the workbook as a DBF file or is there
something else required? If you simply went to the worksheet and did a
SAVEAS to DBF is that acceptable? A macro can easily be written to do
this. Or is there something else the macro need to do.


--
joel
------------------------------------------------------------------------
joel's Profile: http://www.thecodecage.com/forumz/member.php?userid=229
View this thread: http://www.thecodecage.com/forumz/sh...d.php?t=153064

Microsoft Office Help

  #5   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 134
Default Run Code in Another Workbook

Joel - It's a Daily Excel file including data for many Depts, including our
Dept.

I can easily do that manually, but as a Contractor, I'm not here every day.
I want to have a regular Mgr here run a macro to make the DBF when I'm not
here.

I'd like a "template" Excel File that will Find the Daily
File..IE..Data_111109, and then make it a DBF. I saw an Archive Post you had
in Sep this year which will help, but needed automation code to another Excel
file.

Thank you - Bob


"joel" wrote:


Is it sufficient to save the workbook as a DBF file or is there
something else required? If you simply went to the worksheet and did a
SAVEAS to DBF is that acceptable? A macro can easily be written to do
this. Or is there something else the macro need to do.


--
joel
------------------------------------------------------------------------
joel's Profile: http://www.thecodecage.com/forumz/member.php?userid=229
View this thread: http://www.thecodecage.com/forumz/sh...d.php?t=153064

Microsoft Office Help

.



  #6   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1
Default Run Code in Another Workbook


Since today is the eleventh day of the eleventh month I can't tell if
you want the date in month-day-year or day-month-year. Change as
required. Also change the name of the folder.

Sub SaveDBF()

Folder = "c:\temp\"
BaseName = "Data_" & Format(Date, "mmddyy")

BkName = Folder & BaseName & ".xls"
Set bk = Workbooks.Open(Filename:=BkName)

DBaseName = Folder & BkName & ".dbf"

bk.SaveAs Filename:=DBaseName, _
FileFormat:=xlDBF4

bk.Close savechanges:=False
End Sub


--
joel
------------------------------------------------------------------------
joel's Profile: http://www.thecodecage.com/forumz/member.php?userid=229
View this thread: http://www.thecodecage.com/forumz/sh...d.php?t=153064

Microsoft Office Help

  #7   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 134
Default Run Code in Another Workbook

Thank you Joel.

I'm an Access Developer, and use Excel usually only thru
Access-to-Excel-automation.

I'm adding this to my "Knowledge File".

BTW...is there a way to Filter only those Records which, IE, below to Dept
"A", even thought the Excel file contains Depts "A", "B", "C"......"L"

TIA - Bob

"joel" wrote:


Since today is the eleventh day of the eleventh month I can't tell if
you want the date in month-day-year or day-month-year. Change as
required. Also change the name of the folder.

Sub SaveDBF()

Folder = "c:\temp\"
BaseName = "Data_" & Format(Date, "mmddyy")

BkName = Folder & BaseName & ".xls"
Set bk = Workbooks.Open(Filename:=BkName)

DBaseName = Folder & BkName & ".dbf"

bk.SaveAs Filename:=DBaseName, _
FileFormat:=xlDBF4

bk.Close savechanges:=False
End Sub


--
joel
------------------------------------------------------------------------
joel's Profile: http://www.thecodecage.com/forumz/member.php?userid=229
View this thread: http://www.thecodecage.com/forumz/sh...d.php?t=153064

Microsoft Office Help

.

  #8   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1
Default Run Code in Another Workbook


The code below assumes the workbook has a header row, the workbook data
your are saving is on the 1st tab, and the Depts Names are in column A,
and there is at least one row with the deptment name "A". I 'm using
autofilter to filter the data.

Sub SaveDBF()

Folder = "c:\temp\"
BaseName = "Data_" & Format(Date, "mmddyy")

BkName = Folder & BaseName & ".xls"
Set bk = Workbooks.Open(Filename:=BkName)

'create workbook to copy filtered data
Set bk2 = Workbooks.Add(template:=xlWBATWorksheet)

With bk.Sheets(1)
'select autofilter to select Dept A
LastRow = .Range("A" & Rows.Count).End(xlUp).Row
Columns("A:A").AutoFilter
Columns("A:A").AutoFilter Field:=1, Criteria1:="A"
'copy only filtered rows
Rows("1:" & LastRow).SpecialCells(xlCellTypeVisible).Copy _
bk2.Sheets(1).Rows(1)
End With

'create new filename to save file
DBaseName = Folder & BkName & ".dbf"


bk2.SaveAs Filename:=DBaseName, _
FileFormat:=xlDBF4

bk.Close savechanges:=False
bk2.Close savechanges:=False
End Sub


--
joel
------------------------------------------------------------------------
joel's Profile: http://www.thecodecage.com/forumz/member.php?userid=229
View this thread: http://www.thecodecage.com/forumz/sh...d.php?t=153064

Microsoft Office Help

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
How do I call up a line of code that references a cell/range in theactive workbook workbook where I am running my macro from? Lav Excel Programming 2 November 11th 08 05:04 PM
Code to change code in a sheet and workbook module Otto Moehrbach Excel Programming 11 November 11th 07 07:20 PM
run code on opening workbook and apply code to certain sheets Jane Excel Programming 7 August 8th 05 09:15 AM
Code in one workbook to call code in another XL file [email protected] Excel Programming 2 August 1st 05 03:37 PM
Reference code in another workbook from a calling workbook Datasort Excel Programming 1 January 4th 05 01:13 AM


All times are GMT +1. The time now is 01:59 AM.

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"