|
-
Jul 12th, 2009, 04:50 AM
#1
Thread Starter
Hyperactive Member
-
Jul 12th, 2009, 05:52 AM
#2
Re: Visual Basic 6 Through Excel
check out the tutorial, for automating office applications including excel, in the second thread in the office development forum
i do my best to test code works before i post it, but sometimes am unable to do so for some reason, and usually say so if this is the case.
Note code snippets posted are just that and do not include error handling that is required in real world applications, but avoid On Error Resume Next
dim all variables as required as often i have done so elsewhere in my code but only posted the relevant part
come back and mark your original post as resolved if your problem is fixed
pete
-
Jul 12th, 2009, 03:42 PM
#3
Thread Starter
Hyperactive Member
Re: Visual Basic 6 Through Excel
Thank you very much westconn1
First problem solved so far
In process to solve the second one and get the job done.
I used this thread :
http://www.vbforums.com/showthread.php?t=391665
Was so helpful and rich of infos
<--------<< This guy will get promoted so soon
-
Jul 14th, 2009, 01:56 PM
#4
Thread Starter
Hyperactive Member
Re: Visual Basic 6 Through Excel
Guess What ??
Not solved yet !! 
The second question I mean !!
And I'm 100% sure it's so easy..But maybe I'm not making this clear for many.
so plz let me know..
-
Jul 14th, 2009, 04:30 PM
#5
Re: Visual Basic 6 Through Excel
post the code you have so far,
basically
workbookobject.sheets("sheet1").range("b99").value = "my test"
use whatever workbook object you have already created
or if you have created a sheet object, you can omit the workbook object
i do my best to test code works before i post it, but sometimes am unable to do so for some reason, and usually say so if this is the case.
Note code snippets posted are just that and do not include error handling that is required in real world applications, but avoid On Error Resume Next
dim all variables as required as often i have done so elsewhere in my code but only posted the relevant part
come back and mark your original post as resolved if your problem is fixed
pete
-
Jul 17th, 2009, 04:57 AM
#6
Thread Starter
Hyperactive Member
Re: Visual Basic 6 Through Excel
Thanks for your respond
my codes are :
General:
Code:
Dim oXLApp As Excel.Application 'Declare the object variables
Dim oXLBook As Excel.Workbook
Dim oXLSheet As Excel.Worksheet
FormLoad:
Code:
Private Sub Form_Load()
Set oXLApp = New Excel.Application 'Create a new instance of Excel
Set oXLBook = oXLApp.Workbooks.Open("C:\Program Files\2K Writer\2Kilo Form.xls") 'Open an existing workbook
Set oXLSheet = oXLBook.Worksheets(1) 'Work with the first worksheet
End Sub
CommandButton:
Code:
oXLSheet.Range("S8").Formula = Text1.Text 'here is my problem (It works but not like I want it)
I want (text1.text) to be Distributed in S8 , T8 , U8 and V8
let's say text1.text = "NICE"
After Command click it should be :
S8 = N
T8 = I
U8 = C
V8 = E
I hope it's clear now and thank you again.
-
Jul 17th, 2009, 05:53 AM
#7
Re: Visual Basic 6 Through Excel
To work with individual characters from a string use the Mid function, eg:
Code:
MsgBox Mid("hello", 5, 1) 'displays just the 5th character
To determine how long a string is, use the Len function, eg:
Code:
MsgBox Len("hello") 'displays 5
So to work with each character in a string, use a loop:
Code:
Dim intLoop as Integer
For intLoop = 1 to Len(Text1.Text)
MsgBox Mid(Text1.Text, intLoop, 1) 'displays each character in turn
Next intLoop
All you need to do now is change MsgBox to something that puts the data into Excel. Note that it will be easier to use .Cells rather than .Range
-
Jul 17th, 2009, 07:36 AM
#8
Re: Visual Basic 6 Through Excel
if the letters are spaced or anything they could be split into an array and the array assigned to the cells in a range
i do my best to test code works before i post it, but sometimes am unable to do so for some reason, and usually say so if this is the case.
Note code snippets posted are just that and do not include error handling that is required in real world applications, but avoid On Error Resume Next
dim all variables as required as often i have done so elsewhere in my code but only posted the relevant part
come back and mark your original post as resolved if your problem is fixed
pete
-
Jul 18th, 2009, 01:22 PM
#9
Thread Starter
Hyperactive Member
Re: Visual Basic 6 Through Excel
Sorry didn't work !!
The project has many textboxes to be pasted or transferred to the sheet..
I need a small change to this code:
Code:
oXLSheet.Range("S8").Formula = Text1.Text
Or maybe it's something to do with the Excel sheet to make what is pasted in S8 distributed into the individual cells.
If not. How to pick litters from one textbox? like I only want to copy the 5th letter from text1.
Thank you again.
-
Jul 18th, 2009, 05:22 PM
#10
Re: Visual Basic 6 Through Excel
like I only want to copy the 5th letter from text1.
si gave you the code to do that before
letter = mid(text1, 5 ,1)
you can make a loop to put your string into different cells
this will put into row 2
vb Code:
for i = 1 to len(text1) oxlsheet.cells(2, i).value = mid(text1, i, 1) next
i do my best to test code works before i post it, but sometimes am unable to do so for some reason, and usually say so if this is the case.
Note code snippets posted are just that and do not include error handling that is required in real world applications, but avoid On Error Resume Next
dim all variables as required as often i have done so elsewhere in my code but only posted the relevant part
come back and mark your original post as resolved if your problem is fixed
pete
-
Jul 19th, 2009, 01:47 PM
#11
Thread Starter
Hyperactive Member
[RESOLVED]: Visual Basic 6 Through Excel
Thank you very much
my problem got solved finally 
I used this code and it worked very well:
Code:
Dim intLoop As Integer
For intLoop = 1 To Len(Text1)
oXLSheet.Cells(7, 19 + intLoop).Value = Mid(Text1, intLoop, 1)
Next
Best Regards
And thank you again.
Last edited by Joye; Jul 19th, 2009 at 01:51 PM.
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|