| | |
Forum 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.... |
|
| | |

Forum 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 |
|
| | |
Forum 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..... |
|
| | |
Forum 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...
|
|
| | |

Forum 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 |
|
| | |

Forum 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 |
|
| | |
Forum Member
       
Group: Forum Members Last Login: 10/12/2008 2:59:52 AM Posts: 50, Visits: 442 |
| It's work..... Thank you. |
|
| | |

Forum God
       
Group: Forum Members Last Login: Today @ 8:45:13 AM Posts: 349, Visits: 1,705 |
| |
| | |
Forum 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" |
|
| | |

Forum 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 |
|
|