Excel Opening From VB6
Excel Opening From VB6
Excel Opening From VB6
Working with Excel Files Using VB6 - VB 6 sample code - developer Fusion
Join us Sign in India
Owning a computer without programming is like having a kitchen and using only the microwave oven - Charles Petzold Visual Basic 6 Home News Tutorials Code Training User Groups Books Podcasts Forum Jobs
Visual Basic 6
Code
The code is totally self explanatory, In the load event we're going to open the new instance of the excel library and our excel file book1.xls will be accessible from our code. Then we'll use Command1 to retrieve data from book1, please note that you must have some data in the excel file. Similarly Command2 is used to put/replace the data in the excel sheet cells.
' d od e c l a r et h e s ev a r i a b l e sy o un e e dt oa d dar e f e r e n c e ' t ot h em i c r o s o f te x c e l' x x 'o b j e c tl i b r a r y . ' y o un e e dt w ot e x tb o x e sa n dt w oc o m m a n db u t t o n s ' o nt h ef o r m ,a ne x c e lf i l ei nc : \ b o o k 1 . x l s D i mx lA sN e wE x c e l . A p p l i c a t i o n D i mx l s h e e tA sE x c e l . W o r k s h e e t D i mx l w b o o kA sE x c e l . W o r k b o o k P r i v a t eS u bC o m m a n d 1 _ C l i c k ( ) ' t h eb e n i f i to fp l a c i n gn u m b e r si n( r o w ,c o l )i st h a ty o u ' c a nl o o pt h r o u g hd i f f e r e n td i r e c t i o n si fr e q u i r e d .Ic o u l d ' h a v eu s e dc o l u m nn a m e sl i k e" A 1 "' e t c . T e x t 1 . T e x t=x l s h e e t . C e l l s ( 2 ,1 )'r o w2c o l1 T e x t 2 . T e x t=x l s h e e t . C e l l s ( 2 ,2 )'r o w2c o l2 ' d o n ' tf o r g e tt od ot h i so ry o u ' l ln o tb ea b l et oo p e n ' b o o k 1 . x l sa g a i n ,u n t i l ly o ur e s t a r ty o up c . x l . A c t i v e W o r k b o o k . C l o s eF a l s e ," c : \ b o o k 1 . x l s " x l . Q u i t E n dS u b P r i v a t eS u bC o m m a n d 2 _ C l i c k ( ) x l s h e e t . C e l l s ( 2 ,1 )=T e x t 1 . T e x t x l s h e e t . C e l l s ( 2 ,2 )=T e x t 2 . T e x t x l w b o o k . S a v e ' d o n ' tf o r g e tt od ot h i so ry o u ' l ln o tb ea b l et oo p e n ' b o o k 1 . x l sa g a i n ,u n t i l ly o ur e s t a r ty o up c . x l . A c t i v e W o r k b o o k . C l o s eF a l s e ," c : \ b o o k 1 . x l s " x l . Q u i t E n dS u b P r i v a t eS u bF o r m _ L o a d ( ) S e tx l w b o o k=x l . W o r k b o o k s . O p e n ( " c : \ b o o k 1 . x l s " ) S e tx l s h e e t=x l w b o o k . S h e e t s . I t e m ( 1 ) E n dS u b P r i v a t eS u bF o r m _ U n l o a d ( C a n c e lA sI n t e g e r ) S e tx l w b o o k=N o t h i n g S e tx l=N o t h i n g E n dS u b
Contribute
Why not write for us? Or you could submit an event or a user group in your area. Alternatively just tell us what you think!
Web Development
ASP.NET Quickstart Programming news Java programming ASP.NET tutorials C# programming
Developer Jobs
ASP.NET Jobs Java Jobs Developer Jobs
Our tools
We've got automatic conversion tools to convert C# to VB.NET, VB.NET to C#. Also you can compress javascript and compress css and generate sql connection strings. Managed hosting by Everycity
http://www.developerfusion.com/code/5322/working-with-excel-files-using-vb6/
1/1