473,672 Members | 2,577 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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(s XlsPathRoot_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.Applicati on
Dim xlsWorkBk As Excel.Workbook

Set xlsApp = New Excel.Applicati on

Set rsPIW = CurrentDb.OpenR ecordset("t_piw _export_2004")

Set rsFundList = CurrentDb.OpenR ecordset("schd_ fund_list")
Do Until rsFundList.EOF

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

Set qdDelXlsTbl = CurrentDb.Query Defs("schd_purg e")
qdDelXlsTbl.Exe cute

Set qdGenXlsTbl = CurrentDb.Query Defs("load_schd _2004_Part1")
qdGenXlsTbl.Par ameters("prm_fu nd_num") = sFundNum
qdGenXlsTbl.Exe cute

sXlsFilePath = sXlsPathRoot_D & "04d" & sFundNum & "a.xls"
DoCmd.TransferS preadsheet acExport, acSpreadsheetTy peExcel4,
"t_schd_export_ 2004", sXlsFilePath

Set xlsWorkBk = xlsApp.Workbook s.Open(sXlsFile Path)
xlsWorkBk.Works heets(1).Column s(1).Delete
xlsWorkBk.Works heets(1).Rows(1 ).Delete
xlsWorkBk.Save
xlsWorkBk.Close

Set qdDelXlsTbl = CurrentDb.Query Defs("schd_purg e")
qdDelXlsTbl.Exe cute

Set qdGenXlsTbl = CurrentDb.Query Defs("load_schd _2004_Part2")
qdGenXlsTbl.Par ameters("prm_fu nd_num") = sFundNum
qdGenXlsTbl.Exe cute

sXlsFilePath = sXlsPathRoot_D & "04d" & sFundNum & "b.xls"
DoCmd.TransferS preadsheet acExport, acSpreadsheetTy peExcel4,
"t_schd_export_ 2004", sXlsFilePath

Set xlsWorkBk = xlsApp.Workbook s.Open(sXlsFile Path)

xlsWorkBk.Works heets(1).Rows(1 ).Delete

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

Set qdDelXlsTbl = CurrentDb.Query Defs("schh_purg e")
qdDelXlsTbl.Exe cute

Set qdGenXlsTbl = CurrentDb.Query Defs("load_sch_ h2004")
qdGenXlsTbl.Par ameters("prm_fu nd_num") = sFundNum
qdGenXlsTbl.Exe cute

sXlsFilePath = sXlsPathRoot_H & "04h" & sFundNum & ".xls"
DoCmd.TransferS preadsheet acExport, acSpreadsheetTy peExcel4,
"t_schh_export_ 2004", sXlsFilePath

Set xlsWorkBk = xlsApp.Workbook s.Open(sXlsFile Path)
xlsWorkBk.Works heets(1).Rows(1 ).Delete
xlsWorkBk.Save
xlsWorkBk.Close
'
' Do Plan Information Worksheet
'
' rsPIW.MoveFirst
' rsPIW.Edit
' rsPIW.Fields("g ") = Mid(rsFundList. Fields("fund_ei n"), 1,
2)
' rsPIW.Fields("h ") = Mid(rsFundList. Fields("fund_ei n"), 3,
7)
' rsPIW.Fields("i ") = Left(rsFundList .Fields("fund_n m"), 48)
' rsPIW.Fields("j ") = Left(rsFundList .Fields("fund_n m"), 48)
' rsPIW.Update
' sXlsFilePath = sXlsPathRoot_P & "p" & sFundNum & ".xls"
' DoCmd.TransferS preadsheet acExport, acSpreadsheetTy peExcel4,
"t_piw_export_2 000", sXlsFilePath

' Set xlsWorkBk = xlsApp.Workbook s.Open(sXlsFile Path)
' xlsWorkBk.Works heets(1).Rows(1 ).Delete
' xlsWorkBk.Save
' xlsWorkBk.Close

rsFundList.Move Next
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.Scr eenUpdating = False

Application.Dis playAlerts = False

Application.Ref erenceStyle = 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.Pas te

SC = SC + 4

Counter = Counter + 1

If Counter = 8 Then

SR = SR + 1

Counter = 0

SC = 1

Else: SR = SR

End If

Next

Application.Ref erenceStyle = xlA1

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

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

Selection.Clear Contents

Range("A1").Act ivate

Application.Scr eenUpdating = True

Application.Dis playAlerts = 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.Scr eenUpdating = False

Application.Dis playAlerts = False

Application.Ref erenceStyle = 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.Pas te

SC = SC + 6

Counter = Counter + 1

If Counter = 6 Then

SR = SR + 1

Counter = 0

SC = 1

Else: SR = SR

End If

Next

Application.Ref erenceStyle = xlA1

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

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

Selection.Clear Contents

Range("A1").Act ivate

Application.Scr eenUpdating = True

Application.Dis playAlerts = True

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

' Do Schedule D
'

Set qdDelXlsTbl = CurrentDb.Query Defs("schd_purg e")
qdDelXlsTbl.Exe cute

Set qdGenXlsTbl = CurrentDb.Query Defs("load_schd _2004_Part1")
qdGenXlsTbl.Par ameters("prm_fu nd_num") = sFundNum
qdGenXlsTbl.Exe cute

sXlsFilePath = sXlsPathRoot_D & "04d" & sFundNum & "a.xls"
DoCmd.TransferS preadsheet acExport, acSpreadsheetTy peExcel4,
"t_schd_export_ 2004", sXlsFilePath

Set xlsWorkBk = xlsApp.Workbook s.Open(sXlsFile Path)
xlsWorkBk.Works heets(1).Column s(1).Delete
xlsWorkBk.Works heets(1).Rows(1 ).Delete

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

xlsWorkBk.Save
xlsWorkBk.Close

Set qdDelXlsTbl = CurrentDb.Query Defs("schd_purg e")
qdDelXlsTbl.Exe cute

Set qdGenXlsTbl = CurrentDb.Query Defs("load_schd _2004_Part2")
qdGenXlsTbl.Par ameters("prm_fu nd_num") = sFundNum
qdGenXlsTbl.Exe cute

sXlsFilePath = sXlsPathRoot_D & "04d" & sFundNum & "b.xls"
DoCmd.TransferS preadsheet acExport, acSpreadsheetTy peExcel4,
"t_schd_export_ 2004", sXlsFilePath

Set xlsWorkBk = xlsApp.Workbook s.Open(sXlsFile Path)

xlsWorkBk.Works heets(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 1376

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

Similar topics

16
2410
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
2795
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 thoughts about that? "Movement" seems quite an exaggeration. Maybe 2-3 people made some experiments, but nobody within the core Python developers seems to be willing to advocate the introduction of macros. > Why should you care whether the...
11
2844
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 curious about how the following syntactical problem can be solved. It should apply equally to C and C++ as it mainly is a preprocessor-related problem. I tryed to define something similar to the following example: ...
37
3029
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 said that in his code he couldnt use the above words as function names or variable names and got compilation errors. He advised me to use them as enums instead of macros. is he right ??? (in my code the macros are used as return values from fns...
3
2347
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 one central Excel macro repository. What would you guys suggest me do? Should I keep all macros in a centralized unique text file of some sort or is it best to do with SQL server?
1
1543
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 never calls the things. What the heck am I doing wrong? Maybe it's just the late hour but I've been going in circles trying to figure it out. Here's the entire macro module below (be on the look out in case of any word wrap), any help is...
47
32901
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 values only. Of course it is not THAT neccessary functionality, but it could be very useful. greetz Emil
33
8880
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 write type generic functions macros? #define CUBE(I) ( (I) * (I) * (I) ) Is there some more concise set of things where inline functions should be used instead of macros? Multi-statement macros, for example?
80
2911
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
8404
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 effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
8931
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
8828
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 tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
8608
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
1
6238
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
4227
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
4418
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
2819
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
1816
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.