[RESOLVED] Late Binding In Case of Office
Private Sub Command1_Click() 'Declare our Late Bound object(s)
Dim oWB As Object 'Create a new workbook
Dim moApp As Object
Set moApp = CreateObject("Word.Application")
Set oWB = moApp.documents.Add 'Do other stuff to it like populate cells etc. '...
Set oWB = Nothing
End Sub
i have used the above code but a default word document id not generated as soon as i press the command button.
pls help me in this regard.
with regards!
Sethuraman R
Re: Late Binding In Case of Office
Split into its own thread and moved to VB6 and Earlier
Re: Late Binding In Case of Office
This works for me....
vb Code:
Private Sub CommandButton1_Click()
Dim ApWrd As Object, WrdDoc As Object
On Error Resume Next
'~~> Check if Word is already Open
Set ApWrd = GetObject(, "Word.application")
If ApWrd Is Nothing Then
'~~> If no instance of Wordt is found then open one
Set ApWrd = CreateObject("Word.application")
End If
On Error GoTo 0
'~~> Add a new Document
Set WrdDoc = ApWrd.documents.Add
'~~> Display Word
ApWrd.Visible = True
End Sub
Re: Late Binding In Case of Office
Thnks for the code
it works..
million of thanks to you.
with regards!
Sethuraman R
Re: Late Binding In Case of Office
Quote:
Originally Posted by
sethu_r123
Thnks for the code
it works..
million of thanks to you.
with regards!
Sethuraman R
Well then if your query is solved then sethu, you can mark this thread resolved :)
Check the link in my signature on how to do it...
1 Attachment(s)
Re: Late Binding In Case of Office
Hi !
i have 1 more requirement in vb6.
please have a look at the code as enclosed.
i have a text file & when i click a button the contents of this text file should be automatically converted into excel file.
if i have 2 columns in the text file, then in excel sheet also i should have 2 columns.
i have done but the contents are displayed in a single column.
pls help me in this regard.
with regards!
Sethuraman R
Re: Late Binding In Case of Office
here is some code to read the text file
vb Code:
Dim arr2() As Variant, myarr() As String
Open "C:\Documents and Settings\pete\My Documents\test.txt" For Input As 1
myarr = Split(Replace(Input(LOF(1), #1), """", ""), vbNewLine)
Close 1
On Error GoTo errh
ReDim arr2(UBound(myarr), 1)
For i = 0 To UBound(myarr) - 1
arr2(i, 0) = Left(myarr(i), InStr(myarr(i), vbTab) - 1)
arr2(i, 1) = Mid(myarr(i), InStrRev(myarr(i), vbTab) + 1)
Next
set xl = createobject("excel.application")
set wb = xl.workbooks.add
wb.Sheets("sheet1").Range("a1:b" & UBound(myarr)) = arr2
you will need to save and close etc
Re: Late Binding In Case of Office
Hi!
Millions of thanks to you.
it works fine
with regards!
Sethuraman R
Re: Late Binding In Case of Office
Hi!
im stuck with one of the problem in late binding of office.
how to provide the below mentioned feature in vb6 if im using late binding.
dim oRawData as object
With oRawData.Application.Selection
.HorizontalAlignment = xlLeft
.VerticalAlignment = xlBottom
End With
i want the alignment properties.
pls help me in this case.
with regards
Sethuraman R
Re: Late Binding In Case of Office
you need to define the xl contants to their correct value
const xlleft = -4131
or just use the literals
2 Attachment(s)
Re: Late Binding In Case of Office
Hi!
This is w.r.t to my previous post.
i just tried converting the text file into excel file with your code.
but i got an error called input past end of file error -runtime error -62.
i have enclosed the text file.
pls help me in this regard.
its very urgent.
with regards!
Sethuraman R
Re: Late Binding In Case of Office
there are some invalid characters in the text files on line 1 or 2, which indicate end of file
to resolve this, open file for binary as 1, instead of for input, rest of the code is the same
Re: Late Binding In Case of Office
I can give you the answer but I want you to try it first :)
First open MS Excel. Start recording a macro and then open the text file and use the Text To Columns option. Once you are done, simply copy the code to vb6 and amend it accordingly... Trust me, it is very simple. if you get stuck post your code and we will definitely help ;)
Also search the VBF. I have given few examples on Text To Columns .
Hope this helps...
Re: Late Binding In Case of Office
Hi!
i will try my best & if i dont get it i will consult you.
with regards!
Sethuraman R
Re: Late Binding In Case of Office
Hi!
after hours of trying i didnt get it.
pls help me in this regard.
its very urgent.
pls help me.
with regards!
Sethuraman R
1 Attachment(s)
Re: Late Binding In Case of Office
Quote:
Originally Posted by
sethu_r123
Hi!
after hours of trying i didnt get it.
pls help me in this regard.
its very urgent.
pls help me.
with regards!
Sethuraman R
Would your file look like this after converting?
Re: Late Binding In Case of Office
Hi!
Yes the excel sheet should look like that.
pls help me how to achieve it.
its very urgent.
pls help me in this regard
with regards!
Sethuraman R
Re: Late Binding In Case of Office
Ok Here is a very basic example... I have not done much of error handling plus I have not saved the file. I leave that you.
This code will simply open the text file and display it on excel.
Amend it as per your requirements...
vb Code:
Private Sub CommandButton1_Click()
Dim oXLApp As Object
'~~> Establish an EXCEL application object
On Error Resume Next
Set oXLApp = GetObject(, "Excel.Application")
If Err.Number <> 0 Then
Set oXLApp = CreateObject("Excel.Application")
blnEXCEL = True
End If
Err.Clear
On Error GoTo 0
'~~> Change the pathname and file as applicable
oXLApp.Workbooks.OpenText Filename:="C:\Tensile Test080909-145744.txt", _
Origin:=437, StartRow:=1, DataType:=xlDelimited, TextQualifier:= _
xlDoubleQuote, ConsecutiveDelimiter:=False, Tab:=False, Semicolon:=False _
, Comma:=True, Space:=False, Other:=False, FieldInfo:=Array(Array(1, 1), _
Array(2, 1), Array(3, 1)), TrailingMinusNumbers:=True
oXLApp.Visible = True
End Sub
Re: Late Binding In Case of Office
Hi!
Thaks a lot....
im indebted to you....
with regards!
Sethuraman R
Re: Late Binding In Case of Office
You are welcome but simply do not copy and paste the code :)
Try and understand how the code works...
Also If your query is resolved then do remember to mark this thread resolved ;)
Re: Late Binding In Case of Office
HI!
ok i will.
I also have 1 more requirement.
i have developed a software with visual basic 6 as front end, Microsoft Sql server 2000 as backend.
I have a menu in a MDI form & it has got the listing say File-new,open,save,close etc.
all the data will be saved in proper tables.
Now i have a requirement here.
say can i add the field name as a men item from a table in the menu editor.
say i have 4 records in the table with a field called document name.
once a transaction is saved i want to add these document name in the menu editor just like how if you have 5 forms then it will show the listing of the 5 forms in the menu editor.
pls help me in this regard.
its very urgent.
with regards!
Sethuraman R
Re: [RESOLVED] Late Binding In Case of Office
No problem in assisting you but since your query is different than you earlier query, please start a new thread and post this query in that thread ;)
1 Attachment(s)
Re: [RESOLVED] Late Binding In Case of Office
Hi!
this is w.r.t to our previous posts.
you have already given me the code for this.
now i have 1 more requirement here.
please find the code as enclosed.
i want to open an excel document using the late binding concept & i want to automatically print the 1st sheet with the default print settings.
how to do this in vb6.
pls help me in this regard.
its very urgent.
with regards!
Sethuraman R