473,386 Members | 1,860 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,386 software developers and data experts.

Add xls Macros to existing Module.

Hello-

I am fairly new to MS Access and would like to use some macros in .xls
in an Access Module. I have tried to do this on my own but failed to
make it work. I have included the xls macros and the module as well as
where I would like the macros to run. Any input on how to make this
work would be appreciated. This would automate a former 3 step process
into one process.

module

Public Function clean_pn(pn_in As Variant) As String

End Function

Dim pn_out As String

If IsNull(pn_in) Or pn_in = "" Then pn_in = "000"
If pn_in = "VEBA" Then
pn_out = "001"
Else
pn_out = pn_in
End If
clean_pn = pn_out

End Function

Public Sub export_schd04(sXlsPathRoot_P As String, sXlsPathRoot_D As
String, sXlsPathRoot_H As String)
Dim sFundNum As String
Dim sXlsFilePath As String
Dim qdGenXlsTbl As QueryDef
Dim qdDelXlsTbl As QueryDef
Dim rsFundList As Recordset
Dim rsPIW As Recordset
' Dim xlsapp As Application
Dim xlsApp As Excel.Application
Dim xlsWorkBk As Excel.Workbook

Set xlsApp = New Excel.Application

Set rsPIW = CurrentDb.OpenRecordset("t_piw_export_2004")

Set rsFundList = CurrentDb.OpenRecordset("schd_fund_list")
Do Until rsFundList.EOF

sFundNum = rsFundList(0)
'
' Do Schedule D
'

Set qdDelXlsTbl = CurrentDb.QueryDefs("schd_purge")
qdDelXlsTbl.Execute

Set qdGenXlsTbl = CurrentDb.QueryDefs("load_schd_2004_Part1")
qdGenXlsTbl.Parameters("prm_fund_num") = sFundNum
qdGenXlsTbl.Execute

sXlsFilePath = sXlsPathRoot_D & "04d" & sFundNum & "a.xls"
DoCmd.TransferSpreadsheet acExport, acSpreadsheetTypeExcel4,
"t_schd_export_2004", sXlsFilePath

Set xlsWorkBk = xlsApp.Workbooks.Open(sXlsFilePath)
xlsWorkBk.Worksheets(1).Columns(1).Delete
xlsWorkBk.Worksheets(1).Rows(1).Delete
xlsWorkBk.Save
xlsWorkBk.Close

Set qdDelXlsTbl = CurrentDb.QueryDefs("schd_purge")
qdDelXlsTbl.Execute

Set qdGenXlsTbl = CurrentDb.QueryDefs("load_schd_2004_Part2")
qdGenXlsTbl.Parameters("prm_fund_num") = sFundNum
qdGenXlsTbl.Execute

sXlsFilePath = sXlsPathRoot_D & "04d" & sFundNum & "b.xls"
DoCmd.TransferSpreadsheet acExport, acSpreadsheetTypeExcel4,
"t_schd_export_2004", sXlsFilePath

Set xlsWorkBk = xlsApp.Workbooks.Open(sXlsFilePath)

xlsWorkBk.Worksheets(1).Rows(1).Delete

xlsWorkBk.Save
xlsWorkBk.Close
'
' Do Schedule H
'

Set qdDelXlsTbl = CurrentDb.QueryDefs("schh_purge")
qdDelXlsTbl.Execute

Set qdGenXlsTbl = CurrentDb.QueryDefs("load_sch_h2004")
qdGenXlsTbl.Parameters("prm_fund_num") = sFundNum
qdGenXlsTbl.Execute

sXlsFilePath = sXlsPathRoot_H & "04h" & sFundNum & ".xls"
DoCmd.TransferSpreadsheet acExport, acSpreadsheetTypeExcel4,
"t_schh_export_2004", sXlsFilePath

Set xlsWorkBk = xlsApp.Workbooks.Open(sXlsFilePath)
xlsWorkBk.Worksheets(1).Rows(1).Delete
xlsWorkBk.Save
xlsWorkBk.Close
'
' Do Plan Information Worksheet
'
' rsPIW.MoveFirst
' rsPIW.Edit
' rsPIW.Fields("g") = Mid(rsFundList.Fields("fund_ein"), 1,
2)
' rsPIW.Fields("h") = Mid(rsFundList.Fields("fund_ein"), 3,
7)
' rsPIW.Fields("i") = Left(rsFundList.Fields("fund_nm"), 48)
' rsPIW.Fields("j") = Left(rsFundList.Fields("fund_nm"), 48)
' rsPIW.Update
' sXlsFilePath = sXlsPathRoot_P & "p" & sFundNum & ".xls"
' DoCmd.TransferSpreadsheet acExport, acSpreadsheetTypeExcel4,
"t_piw_export_2000", sXlsFilePath

' Set xlsWorkBk = xlsApp.Workbooks.Open(sXlsFilePath)
' xlsWorkBk.Worksheets(1).Rows(1).Delete
' xlsWorkBk.Save
' xlsWorkBk.Close

rsFundList.MoveNext
Loop

MsgBox "Files Generated", vbOKOnly, ""
End Sub

-------------------------------------------------------------------

xls macro A

Sch_D Part 1.

Sub CreateFile()

Dim SN, LN As Variant

Dim Counter, SR, SC As Integer

'SN = Start Name, LN = Last Name, SR = Start Row, SC = Start Column

Application.ScreenUpdating = False

Application.DisplayAlerts = False

Application.ReferenceStyle = xlR1C1

LN = Range("A65536").End(xlUp).Row

SR = 9

SC = 1

Counter = 0

For SN = 9 To LN

Range("A" & SN & ":D" & SN).Select

Selection.Copy

Cells(SR, SC).Select

ActiveSheet.Paste

SC = SC + 4

Counter = Counter + 1

If Counter = 8 Then

SR = SR + 1

Counter = 0

SC = 1

Else: SR = SR

End If

Next

Application.ReferenceStyle = xlA1

Range("AG" & 9, "AG" & SR) = "~5x4"

Range("A" & SR + 1, "D" & 65536).Select

Selection.ClearContents

Range("A1").Activate

Application.ScreenUpdating = True

Application.DisplayAlerts = True

End Sub
-------------------------------------------------------------------

xls Macro 2

Sch_D_Part 2

Sub createfile_2()

Dim SN, LN As Variant

Dim Counter, SR, SC As Integer

'SN = Start Name, LN = Last Name, SR = Start Row, SC = Start Column

Application.ScreenUpdating = False

Application.DisplayAlerts = False

Application.ReferenceStyle = xlR1C1

LN = Range("A65536").End(xlUp).Row

SR = 9

SC = 1

Counter = 0

For SN = 9 To LN

Range("A" & SN & ":F" & SN).Select

Selection.Copy

Cells(SR, SC).Select

ActiveSheet.Paste

SC = SC + 6

Counter = Counter + 1

If Counter = 6 Then

SR = SR + 1

Counter = 0

SC = 1

Else: SR = SR

End If

Next

Application.ReferenceStyle = xlA1

Range("AK" & 9, "AK" & SR) = "~3x4"

Range("A" & SR + 1, "F" & 65536).Select

Selection.ClearContents

Range("A1").Activate

Application.ScreenUpdating = True

Application.DisplayAlerts = True

End Sub
-------------------------------------------------------------------

' Do Schedule D
'

Set qdDelXlsTbl = CurrentDb.QueryDefs("schd_purge")
qdDelXlsTbl.Execute

Set qdGenXlsTbl = CurrentDb.QueryDefs("load_schd_2004_Part1")
qdGenXlsTbl.Parameters("prm_fund_num") = sFundNum
qdGenXlsTbl.Execute

sXlsFilePath = sXlsPathRoot_D & "04d" & sFundNum & "a.xls"
DoCmd.TransferSpreadsheet acExport, acSpreadsheetTypeExcel4,
"t_schd_export_2004", sXlsFilePath

Set xlsWorkBk = xlsApp.Workbooks.Open(sXlsFilePath)
xlsWorkBk.Worksheets(1).Columns(1).Delete
xlsWorkBk.Worksheets(1).Rows(1).Delete

<<<<I WOULD MACRO A TO RUN HERE>>>

xlsWorkBk.Save
xlsWorkBk.Close

Set qdDelXlsTbl = CurrentDb.QueryDefs("schd_purge")
qdDelXlsTbl.Execute

Set qdGenXlsTbl = CurrentDb.QueryDefs("load_schd_2004_Part2")
qdGenXlsTbl.Parameters("prm_fund_num") = sFundNum
qdGenXlsTbl.Execute

sXlsFilePath = sXlsPathRoot_D & "04d" & sFundNum & "b.xls"
DoCmd.TransferSpreadsheet acExport, acSpreadsheetTypeExcel4,
"t_schd_export_2004", sXlsFilePath

Set xlsWorkBk = xlsApp.Workbooks.Open(sXlsFilePath)

xlsWorkBk.Worksheets(1).Rows(1).Delete

<<<<I WOULD MACRO B TO RUN HERE>>>

xlsWorkBk.Save
xlsWorkBk.Close
Any advice would be appreciated.

Nov 13 '05 #1
0 1350

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

16
by: mike420 | last post by:
Tayss wrote: > > app = wxPySimpleApp() > frame = MainWindow(None, -1, "A window") > frame.Show(True) > app.MainLoop() > Why do you need a macro for that? Why don't you just write
37
by: michele.simionato | last post by:
Paul Rubin wrote: > How about macros? Some pretty horrible things have been done in C > programs with the C preprocessor. But there's a movememnt afloat to > add hygienic macros to Python. Got any...
11
by: Ben Hetland | last post by:
....in certain cituations they can be useful if not for anything else, then at least for saving a lot of repetetetetetitititive typing. :-) Beyond the point of "do something better instead", I'm...
37
by: hasadh | last post by:
Hello, probably this may be a simple qn to u all but I need an answer plz. In my software i used macros like OK,TRUE,FALSE,FAILURE . A friend who included this code as a library into his module...
3
by: OhMyGaw | last post by:
Hello Excel/automation Gurus, I am working on an application where I have to keep a centralized database of all macros distributed to user and save the changes back on a nightly basis back to...
1
by: n4ixt | last post by:
I have two macros I used to use in VS 2003. I recently tried to import them for use in VS 2005, but they don't seem to work. I open the macro explorer, right click and do run, but it's like VS...
47
by: Emil | last post by:
Is there any hope that new versions of PHP will support macros similar to C or C++? I've searched manual and didn't find anything except define directive, but it can be used to define constant...
33
by: Robert Seacord | last post by:
When writing C99 code is a reasonable recommendation to use inline functions instead of macros? What sort of things is it still reasonable to do using macros? For example, is it reasonable to...
80
by: pereges | last post by:
Hello, I have the following structure - typedef struct { double x, y, z; }vector; In certain places, I could avoid triplification of code by using an array instead of x, y, z. For eg:
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.