borderAndreaVB free resources for Visual Basic developersborder

borderAndreaVB Visual Basic and VB.NET source code resources - Copyright © 1999-2008 Andrea Tincaniborder

AndreaVB | Forum | News | Downloads | Register | Help | Member List | Statistics | Search | PM | Profile

Print This Topic
Next Topic (how to represent data as pie charts,bar graphs????) New Topic New Poll Post Reply
AndreaVB Forum : VBA (Access, Excel, Word, ...) : How to connect in Excel
Poster Message
noknok
Level: Scholar

Registered: 23-11-2007
Posts: 32

icon How to connect in Excel

Public Sub printform()
Dim xcelprint As New Excel.Application
Dim xlbook As Object
Set xlbook = excelprint.Workbooks.Open("C:\bio\form.xls)

With xcelprint
    .Cells(4, 1) = form1.examtxt.Text
    .Cells(4, 1) = form1.exptxt.Text
End With

xcelprint.PrintOut
Set xlbook = Nothing
Set xlsheet = Nothing
End Sub

this is the code i use to print
but instead of printing the excel i declare, the form is the one printing? why

02-02-2008 at 03:41 AM
View Profile Send Email to User Show All Posts | Quote Reply
noknok
Level: Scholar

Registered: 23-11-2007
Posts: 32
icon Re: How to connect in Excel

Will kinda funny but my inspiration is kieron and the mods here in andreavb

i solve the problem accidentally

this are the steps i made this hope help with the noob like me

Click project - references - look for Microsoft Excel X.X Object Library then ok after that, dpends on you where to put the code in my project i put the code in my Module then call it to the form.

In my module this one i code

Public Const dir = "C:\bio\guide.xls

Public sub forprinting()

set xlbook = GetObject (dir) ' which i declare in my public const
set xlsheet = xlbook.sheets("biodata") biodata is the name of the worksheet in my guide.xls

with xlsheet
   .cells (4, 1) = mainfrm.fnametxt.txt  ' mainfrm name of form of which where im working and fnametxt is the textbox in my mainfrm the .cells (4, 1) the number of cell where u want to put in the excel cell like 4, 1 is A:1 somthing like that

end with

set xlbook = nothing
set xlsheet =nothing

xlsheet.printout

end sub

will thats the code i discover im still studying on it

thanks to lots of code

i expect more sugestion and comment to all mods here thanks

PS. Don not use the printform in your form or naming the forprint into printform instead use other cause that was my first command it print my form  


02-02-2008 at 09:37 AM
View Profile Send Email to User Show All Posts | Quote Reply
stickleprojects
Level: Moderator


Registered: 09-09-2002
Posts: 991
icon Re: How to connect in Excel

Well done Noknok for resolving the problem yourself.
Now please mark this topic as Solved (so other users can find it easier)



____________________________
Build it better, faster, quicker, easier.. then fix it (non-offical MS mission statement)

04-02-2008 at 07:23 AM
View Profile Send Email to User Show All Posts | Quote Reply
AndreaVB Forum : VBA (Access, Excel, Word, ...) : How to connect in Excel
Next Topic (how to represent data as pie charts,bar graphs????) New Topic New Poll Post Reply
Surf To:


Not Logged In? Username: Password: Lost your password?
Partners: Download Actual Software | Free Software Download
borderAndreaVB free resources for Visual Basic developersborder

borderAndreaVB Visual Basic and VB.NET source code resources - Copyright © 1999-2008 Andrea Tincaniborder