473,546 Members | 2,308 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Macro in excell

13 New Member
How to use macro in excel?
Can i get some code to record excell data to vb?

O y, i have project in vb, and i write data in vb, then i transfer it to excell to build chart. This is my code :

Private Sub Command3_Click( )
Set ep = GetObject("C:\D ocuments and Settings\Byon 2007\My Documents\1.xls ")
Set ew = ep.sheets(1)
ew.cells(1, 1) = Label15(0).Capt ion
ew.cells(2, 1) = Label15(1).Capt ion
ew.cells(3, 1) = Label15(2).Capt ion
ew.cells(4, 1) = Label15(3).Capt ion
ew.cells(5, 1) = Label15(4).Capt ion
ew.cells(1, 2) = Label27(0).Capt ion
ew.cells(2, 2) = Label27(1).Capt ion
ew.cells(3, 2) = Label27(2).Capt ion
ew.cells(4, 2) = Label27(3).Capt ion
ew.cells(5, 2) = Label27(4).Capt ion
ew.cells(1, 3) = Text12(0).Text
ew.cells(2, 3) = Text12(1).Text
ew.cells(3, 3) = Text12(2).Text
ew.cells(4, 3) = Text12(3).Text
ew.cells(5, 3) = Text12(4).Text
ew.cells(1, 4) = Label24(0).Capt ion
ew.cells(2, 4) = Label24(1).Capt ion
ew.cells(3, 4) = Label24(2).Capt ion
ew.cells(4, 4) = Label24(3).Capt ion
ew.cells(5, 4) = Label24(4).Capt ion
ew.cells(1, 5) = Label23(0).Capt ion
ew.cells(2, 5) = Label23(1).Capt ion
ew.cells(3, 5) = Label23(2).Capt ion
ew.cells(4, 5) = Label23(3).Capt ion
ew.cells(5, 5) = Label23(4).Capt ion
ew.cells(1, 6) = Label17(0).Capt ion
ew.cells(2, 6) = Label17(1).Capt ion
ew.cells(3, 6) = Label17(2).Capt ion
ew.cells(4, 6) = Label17(3).Capt ion
ew.cells(5, 6) = Label17(4).Capt ion
ep.application. Visible = True
End Sub

what is wrong with this code? Coz the application is not visible when i click the command button.

As u know, i want to change my data in vb and when i click this command button, the application and the chart in excell is visible and change itself according to data in vb....

Thanks for your help.
Mar 4 '08 #1
2 1347
kadghar
1,295 Recognized Expert Top Contributor
How to use macro in excel?
Can i get some code to record excell data to vb?

O y, i have project in vb, and i write data in vb, then i transfer it to excell to build chart. This is my code :

Private Sub Command3_Click( )
Set ep = GetObject("C:\D ocuments and Settings\Byon 2007\My Documents\1.xls ")
Set ew = ep.sheets(1)
ew.cells(1, 1) = Label15(0).Capt ion
ew.cells(2, 1) = Label15(1).Capt ion
ew.cells(3, 1) = Label15(2).Capt ion
ew.cells(4, 1) = Label15(3).Capt ion
ew.cells(5, 1) = Label15(4).Capt ion
ew.cells(1, 2) = Label27(0).Capt ion
ew.cells(2, 2) = Label27(1).Capt ion
ew.cells(3, 2) = Label27(2).Capt ion
ew.cells(4, 2) = Label27(3).Capt ion
ew.cells(5, 2) = Label27(4).Capt ion
ew.cells(1, 3) = Text12(0).Text
ew.cells(2, 3) = Text12(1).Text
ew.cells(3, 3) = Text12(2).Text
ew.cells(4, 3) = Text12(3).Text
ew.cells(5, 3) = Text12(4).Text
ew.cells(1, 4) = Label24(0).Capt ion
ew.cells(2, 4) = Label24(1).Capt ion
ew.cells(3, 4) = Label24(2).Capt ion
ew.cells(4, 4) = Label24(3).Capt ion
ew.cells(5, 4) = Label24(4).Capt ion
ew.cells(1, 5) = Label23(0).Capt ion
ew.cells(2, 5) = Label23(1).Capt ion
ew.cells(3, 5) = Label23(2).Capt ion
ew.cells(4, 5) = Label23(3).Capt ion
ew.cells(5, 5) = Label23(4).Capt ion
ew.cells(1, 6) = Label17(0).Capt ion
ew.cells(2, 6) = Label17(1).Capt ion
ew.cells(3, 6) = Label17(2).Capt ion
ew.cells(4, 6) = Label17(3).Capt ion
ew.cells(5, 6) = Label17(4).Capt ion
ep.application. Visible = True
End Sub

what is wrong with this code? Coz the application is not visible when i click the command button.

As u know, i want to change my data in vb and when i click this command button, the application and the chart in excell is visible and change itself according to data in vb....

Thanks for your help.
It seems fine to me, but i'd do it this way (it might help you):
Expand|Select|Wrap|Line Numbers
  1. Private Sub Command3_Click()
  2.    dim obj1 as object
  3.    set obj1 = createobject("excel.application")
  4.    obj1.workbooks.open("C:\Documents and Settings\Byon 2007\My Documents\1.xls")
  5.    with obj1.workbooks(1).worksheets(1)
  6.    .cells(1, 1) = Label15(0).Caption
  7.    .cells(2, 1) = Label15(1).Caption
  8.    .cells(3, 1) = Label15(2).Caption
  9.    .cells(4, 1) = Label15(3).Caption
  10.    .cells(5, 1) = Label15(4).Caption
  11.    .cells(1, 2) = Label27(0).Caption
  12.    .cells(2, 2) = Label27(1).Caption
  13.    .cells(3, 2) = Label27(2).Caption
  14.    .cells(4, 2) = Label27(3).Caption
  15.    .cells(5, 2) = Label27(4).Caption
  16.    .cells(1, 3) = Text12(0).Text
  17.    .cells(2, 3) = Text12(1).Text
  18.    .cells(3, 3) = Text12(2).Text
  19.    .cells(4, 3) = Text12(3).Text
  20.    .cells(5, 3) = Text12(4).Text
  21.    .cells(1, 4) = Label24(0).Caption
  22.    .cells(2, 4) = Label24(1).Caption
  23.    .cells(3, 4) = Label24(2).Caption
  24.    .cells(4, 4) = Label24(3).Caption
  25.    .cells(5, 4) = Label24(4).Caption
  26.    .cells(1, 5) = Label23(0).Caption
  27.    .cells(2, 5) = Label23(1).Caption
  28.    .cells(3, 5) = Label23(2).Caption
  29.    .cells(4, 5) = Label23(3).Caption
  30.    .cells(5, 5) = Label23(4).Caption
  31.    .cells(1, 6) = Label17(0).Caption
  32.    .cells(2, 6) = Label17(1).Caption
  33.    .cells(3, 6) = Label17(2).Caption
  34.    .cells(4, 6) = Label17(3).Caption
  35.    .cells(5, 6) = Label17(4).Caption
  36.    end with
  37.    obj1.Visible = True
  38. End Sub
Mar 4 '08 #2
Bram2008
13 New Member
OK Big Thanks.....
It works.
Mar 5 '08 #3

Sign in to post your reply or Sign up for a free account.

Similar topics

3
1712
by: Savas Ates | last post by:
i cant delete data from excell which i use as a database with asp .. i encounter an error report about isam. how can i delete data from excell help meee!
2
1384
by: alvis | last post by:
I need to write a windows service that will read a excell spreadsheet and either update a row in my sql db or insert the row. My question is how do i read excell spreadsheet row by row in VB dotnet
1
1624
by: Mustafa | last post by:
I have an ASP script where i am generating the excell sheet dynamically i am passing some column header text which is long text so i want it to display it vertically in column (cell).In excell i can do it manually using format cell , alignment, orientation =90. the same i want to display through my asp page dynamically. thanks Mustafa
8
6541
by: Nick M | last post by:
Hello All, Excellent info here Thanks! I am very new to using access in general and I am on a learning curve. I'm trying to import an excel workbook (with worksheets) into an access db via a macro. (I'll get to using VB later on). What I would like to do is import a single workbook w/three seperate worksheets into three seperate access...
2
1366
by: Robert Halstead | last post by:
Hi guys, I have a asp.net web app and it's connecting to an excell 2003 document (in another folder) via OleDataAdapter. Everything works and all, it's just that when I shutdown IE and try to access the excell document, asp.net seems to still keep it and won't release it. Excell gives some error saying it can't access it, but It's when I...
0
1100
by: Delforce | last post by:
Hi all, My application allows you to create a new excel file and then double click it in the list view to start it in excell. If the excell file is an existing one then I can start it now problem. The problem is when I create a new excel file in my application and try and double click it excell starts and has the name of my newly created...
2
2668
by: glibo | last post by:
I am trying to change the tab name when i open a excell spread sheet on the run time in c#. I changed it in the code: Response.AddHeader("content-disposition","filename=" + sFileName + ".xls"); But it works only on save mode but on the display mode still display the name of the page i am calling this excell spread sheet, in other words i see...
1
1449
Ali Rizwan
by: Ali Rizwan | last post by:
Hi all, I m creating a database. The data for database will fetched from an excell sheet. Now how can i read an excell sheet and update my database with that excell sheet. Or I want to show all records of excell sheet in a listbox having a title of speecific text like "Names". Thanx >> ALI <<
1
2806
by: asedt | last post by:
With my Excel macro and two text files I want to create a new textfile containing the first textfile then text from the sheet and then the second textfile. My problem is that i don't know how to append the second textfile. Sub mysub() Dim TempString As String 'Open the first file Dim fileA As Integer
0
7504
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main...
0
7435
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...
0
7947
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...
0
7792
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the...
0
6026
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, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then...
0
5080
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 then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert...
0
3491
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...
1
1046
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
0
747
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...

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.