473,511 Members | 17,164 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

visual basic problem

I have code that exports data to excel and formats it. I originally
put it into the on click method; however, it has not gotten too large.
I want to split it out into different modules; however, I am not sure
how to start formatting an open excel file. What I have done is export
the data, open the file and then do some initial formatting. The next
"function"? would be to do more formatting on the open excel file. Is
there a way to do this? It seems like I need to re-declare the excel
file somehow.
Thanks for any help you can give.

Nov 13 '05 #1
6 1542
Apgoodb,
Oh my, yes. If you create an instance of Excel in your VBA code that then
opens the worksheet for you there is a huge amount of stuff you can do.

<ap*****@yahoo.com> wrote in message
news:11*********************@f14g2000cwb.googlegro ups.com...
I have code that exports data to excel and formats it. I originally
put it into the on click method; however, it has not gotten too large.
I want to split it out into different modules; however, I am not sure
how to start formatting an open excel file. What I have done is export
the data, open the file and then do some initial formatting. The next
"function"? would be to do more formatting on the open excel file. Is
there a way to do this? It seems like I need to re-declare the excel
file somehow.
Thanks for any help you can give.

Nov 13 '05 #2
Also, here is some of the code that I have:
on click event:
Dim strSpreadsheet As String
Dim xlapp As New Excel.Application
strSpreadsheet = [txtdirectory]
xlapp.Visible = True
xlapp.Workbooks.Open strSpreadsheet
'add client and report names to header
Dim clientname As String
Dim reportnamename As String
clientname = Trim(DLookup("[client_name]", "clients", "[client_id] =" &
[client]))
reportnamename = Trim(DLookup("[report_name]", "reports", "[report_id]
=" & [report]))
xlapp.Application.worksheets("Summary").Range("a1" ).Value = clientname

function code:
Function pcpfunction()
'format individual sheets
xlapp.Application.Sheets("PCP_High").Select
xlapp.Application.worksheets("PCP_High").Range("d1 :f1").MergeCells =
True

It seems like I need to declare what xlapp is in the function?
Thanks,

Nov 13 '05 #3
Apgood,
Isn't that what "Dim xlapp as New Excel.Application" does?

<ap*****@yahoo.com> wrote in message
news:11**********************@f14g2000cwb.googlegr oups.com...
Also, here is some of the code that I have:
on click event:
Dim strSpreadsheet As String
Dim xlapp As New Excel.Application

Nov 13 '05 #4
You can do this in a couple of ways.
1. You can declare xlapp outside of both procedures, at the top of the form
module, if all procedures will be within the same form module, or at the top
of a standard module.
2. You can pass xlapp as an argument to the function.

What you don't want to do is declare it a second time in the second
function -
that will give you a new instance of Excel, which won't know anything
about what you've done in the first one!

HTH

<ap*****@yahoo.com> wrote in message
news:11**********************@f14g2000cwb.googlegr oups.com...
Also, here is some of the code that I have:
on click event:
Dim strSpreadsheet As String
Dim xlapp As New Excel.Application
strSpreadsheet = [txtdirectory]
xlapp.Visible = True
xlapp.Workbooks.Open strSpreadsheet
'add client and report names to header
Dim clientname As String
Dim reportnamename As String
clientname = Trim(DLookup("[client_name]", "clients", "[client_id] =" &
[client]))
reportnamename = Trim(DLookup("[report_name]", "reports", "[report_id]
=" & [report]))
xlapp.Application.worksheets("Summary").Range("a1" ).Value = clientname

function code:
Function pcpfunction()
'format individual sheets
xlapp.Application.Sheets("PCP_High").Select
xlapp.Application.worksheets("PCP_High").Range("d1 :f1").MergeCells =
True

It seems like I need to declare what xlapp is in the function?
Thanks,

Nov 13 '05 #5
I don't think I can declare it outside because the file name is random
based upon where the user wants to save it. How would I do option 2 to
pass the argument to the function?
Thanks,

MacDermott wrote:
You can do this in a couple of ways.
1. You can declare xlapp outside of both procedures, at the top of the form module, if all procedures will be within the same form module, or at the top of a standard module.
2. You can pass xlapp as an argument to the function.

What you don't want to do is declare it a second time in the second
function -
that will give you a new instance of Excel, which won't know anything about what you've done in the first one!

HTH

<ap*****@yahoo.com> wrote in message
news:11**********************@f14g2000cwb.googlegr oups.com...
Also, here is some of the code that I have:
on click event:
Dim strSpreadsheet As String
Dim xlapp As New Excel.Application
strSpreadsheet = [txtdirectory]
xlapp.Visible = True
xlapp.Workbooks.Open strSpreadsheet
'add client and report names to header
Dim clientname As String
Dim reportnamename As String
clientname = Trim(DLookup("[client_name]", "clients", "[client_id] =" & [client]))
reportnamename = Trim(DLookup("[report_name]", "reports", "[report_id] =" & [report]))
xlapp.Application.worksheets("Summary").Range("a1" ).Value = clientname
function code:
Function pcpfunction()
'format individual sheets
xlapp.Application.Sheets("PCP_High").Select
xlapp.Application.worksheets("PCP_High").Range("d1 :f1").MergeCells = True

It seems like I need to declare what xlapp is in the function?
Thanks,


Nov 13 '05 #6
"Declaring" it merely means using a Dim or Public (or Private) statement to
allocate memory for it.
For example:
Public xlapp as Excel.Application
or
Dim xlapp as Object
If you do this outside of the procedure(s), you can then instantiate it
inside a procedure, and references from other procedures will use the same
instance.

To pass it as an argument, you would declare your second procedure with an
argument, e.g.
Function pcpfunction(xlapp as Excel.application)
You'd call it from your first function with something like this:
pcpfunction xlapp

HTH
- Turtle

<ap*****@yahoo.com> wrote in message
news:11********************@f14g2000cwb.googlegrou ps.com...
I don't think I can declare it outside because the file name is random
based upon where the user wants to save it. How would I do option 2 to
pass the argument to the function?
Thanks,

MacDermott wrote:
You can do this in a couple of ways.
1. You can declare xlapp outside of both procedures, at the top of

the form
module, if all procedures will be within the same form module, or at

the top
of a standard module.
2. You can pass xlapp as an argument to the function.

What you don't want to do is declare it a second time in the second
function -
that will give you a new instance of Excel, which won't know

anything
about what you've done in the first one!

HTH

<ap*****@yahoo.com> wrote in message
news:11**********************@f14g2000cwb.googlegr oups.com...
Also, here is some of the code that I have:
on click event:
Dim strSpreadsheet As String
Dim xlapp As New Excel.Application
strSpreadsheet = [txtdirectory]
xlapp.Visible = True
xlapp.Workbooks.Open strSpreadsheet
'add client and report names to header
Dim clientname As String
Dim reportnamename As String
clientname = Trim(DLookup("[client_name]", "clients", "[client_id] =" & [client]))
reportnamename = Trim(DLookup("[report_name]", "reports", "[report_id] =" & [report]))
xlapp.Application.worksheets("Summary").Range("a1" ).Value = clientname
function code:
Function pcpfunction()
'format individual sheets
xlapp.Application.Sheets("PCP_High").Select
xlapp.Application.worksheets("PCP_High").Range("d1 :f1").MergeCells = True

It seems like I need to declare what xlapp is in the function?
Thanks,

Nov 13 '05 #7

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

Similar topics

10
4351
by: John | last post by:
I have a problem, it's not with any code I have because... there is no code. When I run a blank visual basic 6 form, it opens up just fine. When I add a text box, a caption, and a button... it...
8
5654
by: delete table with Visual Basic 6 | last post by:
Dear developer, I have an error message when I try to delete or drop Microsoft Access XP table with ADOX in Visual Basic 6. I use the ADOX.Catalog and ADOX.table to create and delete or drop table...
26
10820
by: Bruno Jouhier [MVP] | last post by:
I'm currently experiencing a strange phenomenon: At my Office, Visual Studio takes a very long time to compile our solution (more than 1 minute for the first project). At home, Visual Studio...
2
4861
by: frossberg | last post by:
Hello! I tried to install the Visual Basic.NET Resource Kit (http://msdn.microsoft.com/vbasic/vbrkit/) but obviously something went very wrong and now it sems impossible both to repair and to...
4
1711
by: MikeB | last post by:
I've been all over the net with this question, I hope I've finally found a group where I can ask about Visual Basic 2005. I'm at uni and we're working with Visual Basic 2005. I have some books, ...
1
4541
by: praful pathak | last post by:
i i am praful pathak,porbandar i want to develop my own cross tab report in visual basic 6 i know what developed query from ms access but how to coded in visual basic in designing time and how to...
4
2142
by: sqlguy | last post by:
Why do we have to contact MS for a problem that has been with this compiler from at least the beta of VS 20005. I am so sick and tired of the 30 - 40 clicks it takes to dismiss VS when there is a...
97
5418
by: Master Programmer | last post by:
An friend insider told me that VB is to be killled off within 18 months. I guess this makes sence now that C# is here. I believe it and am actualy surprised they ever even included it in VS 2003 in...
6
2508
by: Salman | last post by:
I would like to know how I can distribute the application that I create with Visual C++ express edition. I checked the menu options to find a deploy option similar to the one found on the Visual...
1
2054
by: Ronm | last post by:
Hey Guys, I have a problem which has been driving me crazy for the last days. I'm working on a small project involving: Visual Basic Acces Database ASP and adobe/macromedia Flash,
0
7423
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...
1
7081
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...
0
5668
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
1
5066
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...
0
4737
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...
0
3225
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...
0
3213
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
781
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
0
447
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...

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.