Visual Basic Code , VB.NET Code, VB Code
  Home   :  Code   :  Forums   :  Submit   :  Mailing List   :  About   :  Contact
A1VBCode Forums
Home      Members   Calendar   Who's On
Welcome Guest ( Login | Register )
      

Home » Visual Basic (VB 4/5/6) » General Visual Basic » Put number or name in MS Excel using VB

12 posts, Page 1 of 2. 12»»

Put number or name in MS Excel using VBExpand / Collapse
Author
Message
Posted 10/8/2008 5:10:51 AM
Forum Member

Forum MemberForum MemberForum MemberForum MemberForum MemberForum MemberForum MemberForum Member

Group: Forum Members
Last Login: 10/12/2008 2:59:52 AM
Posts: 50, Visits: 442
Hi,

How to link between VB and MS Excel? If I press 'John' button, it will store the name 'John' in MS Excel....

Any simple code for this?

Thanks a lot....

Post #25935
Posted 10/11/2008 1:31:27 AM


Forum God

Forum GodForum GodForum GodForum GodForum GodForum GodForum GodForum God

Group: Forum Members
Last Login: Today @ 8:45:13 AM
Posts: 349, Visits: 1,705
This is an example of Late Binding. I think you can figure out how to put what you want in a CommandButton event.

Option Explicit
Dim oXLApp As Object
Dim oXLBook As Object
Dim oXLSheet As Object
Dim oXLRange As Object
Dim strFileName As String
Dim strData As String


Private Sub Form_Load()
    strFileName = "C:\Program Files\Microsoft Visual Studio\VB98\MyExcelBook"
    strData = "Test string sent from VB"
         Set oXLApp = CreateObject("Excel.Application")
         Set oXLBook = oXLApp.Workbooks.Open(strFileName)
         Set oXLSheet = oXLApp.Sheets("Sheet1")
         Set oXLRange = oXLSheet.Range("C1:C2")
             oXLSheet.Cells(2, 1).Value = strData
            ' oXLApp.Visible = True

             oXLBook.Close SaveChanges:=True
         Set oXLRange = Nothing
         Set oXLSheet = Nothing
         Set oXLBook = Nothing
             oXLApp.Quit
     Set oXLApp = Nothing
End Sub



 

"So much to learn. So little time to do it. Wise men know it's later than one thinks"!

***Vote here to make Keith a Moderator***

http://www.a1vbcode.com/vbforums/FindPost23630.aspx

Post #25962
Posted 10/11/2008 2:35:35 AM
Forum Member

Forum MemberForum MemberForum MemberForum MemberForum MemberForum MemberForum MemberForum Member

Group: Forum Members
Last Login: 10/12/2008 2:59:52 AM
Posts: 50, Visits: 442
Hi,

I cannot open the excelbook file...have checked my folder path and there is no such file there....any optional path?

Thanks a lot.....

Post #25963
Posted 10/11/2008 3:12:58 AM
Forum Member

Forum MemberForum MemberForum MemberForum MemberForum MemberForum MemberForum MemberForum Member

Group: Forum Members
Last Login: 10/12/2008 2:59:52 AM
Posts: 50, Visits: 442
It works but how to link the button? Confuse...

Post #25964
Posted 10/11/2008 9:01:17 AM


Forum God

Forum GodForum GodForum GodForum GodForum GodForum GodForum GodForum God

Group: Forum Members
Last Login: Today @ 8:45:13 AM
Posts: 349, Visits: 1,705
thye (10/11/2008)
Hi,

I cannot open the excelbook file...have checked my folder path and there is no such file there....any optional path?

Thanks a lot.....

Since you posted this reply you have posted another reply stating that it "It Works". So am I to assume that you figured out that you have to create the file named 'MyExcelBook' in the directory shown?

 

"So much to learn. So little time to do it. Wise men know it's later than one thinks"!

***Vote here to make Keith a Moderator***

http://www.a1vbcode.com/vbforums/FindPost23630.aspx

Post #25977
Posted 10/11/2008 9:12:21 AM


Forum God

Forum GodForum GodForum GodForum GodForum GodForum GodForum GodForum God

Group: Forum Members
Last Login: Today @ 8:45:13 AM
Posts: 349, Visits: 1,705
thye (10/11/2008)
It works but how to link the button? Confuse...

Just move all the Form_Load() code to a Command1_Click event.

 

"So much to learn. So little time to do it. Wise men know it's later than one thinks"!

***Vote here to make Keith a Moderator***

http://www.a1vbcode.com/vbforums/FindPost23630.aspx

Post #25978
Posted 10/12/2008 2:59:51 AM
Forum Member

Forum MemberForum MemberForum MemberForum MemberForum MemberForum MemberForum MemberForum Member

Group: Forum Members
Last Login: 10/12/2008 2:59:52 AM
Posts: 50, Visits: 442
It's work.....

Thank you.

Post #25991
Posted 10/12/2008 8:31:29 AM


Forum God

Forum GodForum GodForum GodForum GodForum GodForum GodForum GodForum God

Group: Forum Members
Last Login: Today @ 8:45:13 AM
Posts: 349, Visits: 1,705
You're welcome Thye.

 

"So much to learn. So little time to do it. Wise men know it's later than one thinks"!

***Vote here to make Keith a Moderator***

http://www.a1vbcode.com/vbforums/FindPost23630.aspx

Post #25992
Posted 10/21/2008 9:15:22 AM
Forum Newbie

Forum NewbieForum NewbieForum NewbieForum NewbieForum NewbieForum NewbieForum NewbieForum Newbie

Group: Forum Members
Last Login: 11/5/2008 4:04:03 AM
Posts: 7, Visits: 14
Hellow friends!

I'm new on this forum and English is not my native language. So, I'm sorrow for my errors.

Well, question is, how I can read info from different cells and different sheet's in the book?

For example, I need to read cell A1 located on Sheet "Sheet1" and cell B2 from "Sheet2"

Post #26042
Posted 10/21/2008 10:49:36 AM


Forum God

Forum GodForum GodForum GodForum GodForum GodForum GodForum GodForum God

Group: Forum Members
Last Login: Today @ 8:45:13 AM
Posts: 349, Visits: 1,705
Welcome to A1 vlaius. You should not have posted your question in someone else's post. Please repost as a new topic.

 

"So much to learn. So little time to do it. Wise men know it's later than one thinks"!

***Vote here to make Keith a Moderator***

http://www.a1vbcode.com/vbforums/FindPost23630.aspx

Post #26043