Results 1 to 23 of 23

Thread: [RESOLVED] Late Binding In Case of Office

  1. #1

    Thread Starter
    Addicted Member
    Join Date
    Feb 2009
    Location
    Bangalore India
    Posts
    201

    Resolved [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

  2. #2
    I'm about to be a PowerPoster! Hack's Avatar
    Join Date
    Aug 2001
    Location
    Searching for mendhak
    Posts
    58,333

    Re: Late Binding In Case of Office

    Split into its own thread and moved to VB6 and Earlier

  3. #3
    Discovering Life Siddharth Rout's Avatar
    Join Date
    Feb 2005
    Location
    Mumbai, India
    Posts
    12,001

    Re: Late Binding In Case of Office

    This works for me....

    vb Code:
    1. Private Sub CommandButton1_Click()
    2.     Dim ApWrd As Object, WrdDoc As Object
    3.    
    4.     On Error Resume Next
    5.    
    6.     '~~> Check if Word is already Open
    7.     Set ApWrd = GetObject(, "Word.application")
    8.        
    9.     If ApWrd Is Nothing Then
    10.         '~~> If no instance of Wordt is found then open one
    11.         Set ApWrd = CreateObject("Word.application")
    12.     End If
    13.    
    14.     On Error GoTo 0
    15.    
    16.     '~~> Add a new Document
    17.     Set WrdDoc = ApWrd.documents.Add
    18.    
    19.     '~~> Display Word
    20.     ApWrd.Visible = True
    21. End Sub
    A good exercise for the Heart is to bend down and help another up...
    Please Mark your Thread "Resolved", if the query is solved


    MyGear:
    ★ CPU ★ Ryzen 5 5800X
    ★ GPU ★ NVIDIA GeForce RTX 3080 TI Founder Edition
    ★ RAM ★ G. Skill Trident Z RGB 32GB 3600MHz
    ★ MB ★ ASUS TUF GAMING X570 (WI-FI) ATX Gaming
    ★ Storage ★ SSD SB-ROCKET-1TB + SEAGATE 2TB Barracuda IHD
    ★ Cooling ★ NOCTUA NH-D15 CHROMAX BLACK 140mm + 10 of Noctua NF-F12 PWM
    ★ PSU ★ ANTEC HCG-1000-EXTREME 1000 Watt 80 Plus Gold Fully Modular PSU
    ★ Case ★ LIAN LI PC-O11 DYNAMIC XL ROG (BLACK) (G99.O11DXL-X)
    ★ Monitor ★ LG Ultragear 27" 240Hz Gaming Monitor
    ★ Keyboard ★ TVS Electronics Gold Keyboard
    ★ Mouse ★ Logitech G502 Hero

  4. #4

    Thread Starter
    Addicted Member
    Join Date
    Feb 2009
    Location
    Bangalore India
    Posts
    201

    Arrow Re: Late Binding In Case of Office

    Thnks for the code
    it works..

    million of thanks to you.

    with regards!
    Sethuraman R

  5. #5
    Discovering Life Siddharth Rout's Avatar
    Join Date
    Feb 2005
    Location
    Mumbai, India
    Posts
    12,001

    Re: Late Binding In Case of Office

    Quote Originally Posted by sethu_r123 View Post
    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...
    A good exercise for the Heart is to bend down and help another up...
    Please Mark your Thread "Resolved", if the query is solved


    MyGear:
    ★ CPU ★ Ryzen 5 5800X
    ★ GPU ★ NVIDIA GeForce RTX 3080 TI Founder Edition
    ★ RAM ★ G. Skill Trident Z RGB 32GB 3600MHz
    ★ MB ★ ASUS TUF GAMING X570 (WI-FI) ATX Gaming
    ★ Storage ★ SSD SB-ROCKET-1TB + SEAGATE 2TB Barracuda IHD
    ★ Cooling ★ NOCTUA NH-D15 CHROMAX BLACK 140mm + 10 of Noctua NF-F12 PWM
    ★ PSU ★ ANTEC HCG-1000-EXTREME 1000 Watt 80 Plus Gold Fully Modular PSU
    ★ Case ★ LIAN LI PC-O11 DYNAMIC XL ROG (BLACK) (G99.O11DXL-X)
    ★ Monitor ★ LG Ultragear 27" 240Hz Gaming Monitor
    ★ Keyboard ★ TVS Electronics Gold Keyboard
    ★ Mouse ★ Logitech G502 Hero

  6. #6

    Thread Starter
    Addicted Member
    Join Date
    Feb 2009
    Location
    Bangalore India
    Posts
    201

    Arrow 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
    Attached Files Attached Files

  7. #7
    PowerPoster
    Join Date
    Dec 2004
    Posts
    25,618

    Re: Late Binding In Case of Office

    here is some code to read the text file

    vb Code:
    1. Dim arr2() As Variant, myarr() As String
    2. Open "C:\Documents and Settings\pete\My Documents\test.txt" For Input As 1
    3. myarr = Split(Replace(Input(LOF(1), #1), """", ""), vbNewLine)
    4. Close 1
    5. On Error GoTo errh
    6. ReDim arr2(UBound(myarr), 1)
    7. For i = 0 To UBound(myarr) - 1
    8.    
    9.     arr2(i, 0) = Left(myarr(i), InStr(myarr(i), vbTab) - 1)
    10.     arr2(i, 1) = Mid(myarr(i), InStrRev(myarr(i), vbTab) + 1)
    11. Next
    12. set xl = createobject("excel.application")
    13. set wb = xl.workbooks.add
    14. wb.Sheets("sheet1").Range("a1:b" & UBound(myarr)) = arr2
    you will need to save and close etc
    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

  8. #8

    Thread Starter
    Addicted Member
    Join Date
    Feb 2009
    Location
    Bangalore India
    Posts
    201

    Arrow Re: Late Binding In Case of Office

    Hi!
    Millions of thanks to you.
    it works fine

    with regards!
    Sethuraman R

  9. #9

    Thread Starter
    Addicted Member
    Join Date
    Feb 2009
    Location
    Bangalore India
    Posts
    201

    Arrow 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

  10. #10
    PowerPoster
    Join Date
    Dec 2004
    Posts
    25,618

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

  11. #11

    Thread Starter
    Addicted Member
    Join Date
    Feb 2009
    Location
    Bangalore India
    Posts
    201

    Arrow 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
    Attached Files Attached Files

  12. #12
    PowerPoster
    Join Date
    Dec 2004
    Posts
    25,618

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

  13. #13
    Discovering Life Siddharth Rout's Avatar
    Join Date
    Feb 2005
    Location
    Mumbai, India
    Posts
    12,001

    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...
    A good exercise for the Heart is to bend down and help another up...
    Please Mark your Thread "Resolved", if the query is solved


    MyGear:
    ★ CPU ★ Ryzen 5 5800X
    ★ GPU ★ NVIDIA GeForce RTX 3080 TI Founder Edition
    ★ RAM ★ G. Skill Trident Z RGB 32GB 3600MHz
    ★ MB ★ ASUS TUF GAMING X570 (WI-FI) ATX Gaming
    ★ Storage ★ SSD SB-ROCKET-1TB + SEAGATE 2TB Barracuda IHD
    ★ Cooling ★ NOCTUA NH-D15 CHROMAX BLACK 140mm + 10 of Noctua NF-F12 PWM
    ★ PSU ★ ANTEC HCG-1000-EXTREME 1000 Watt 80 Plus Gold Fully Modular PSU
    ★ Case ★ LIAN LI PC-O11 DYNAMIC XL ROG (BLACK) (G99.O11DXL-X)
    ★ Monitor ★ LG Ultragear 27" 240Hz Gaming Monitor
    ★ Keyboard ★ TVS Electronics Gold Keyboard
    ★ Mouse ★ Logitech G502 Hero

  14. #14

    Thread Starter
    Addicted Member
    Join Date
    Feb 2009
    Location
    Bangalore India
    Posts
    201

    Arrow 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

  15. #15

    Thread Starter
    Addicted Member
    Join Date
    Feb 2009
    Location
    Bangalore India
    Posts
    201

    Arrow 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

  16. #16
    Discovering Life Siddharth Rout's Avatar
    Join Date
    Feb 2005
    Location
    Mumbai, India
    Posts
    12,001

    Re: Late Binding In Case of Office

    Quote Originally Posted by sethu_r123 View Post
    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?
    Attached Files Attached Files
    A good exercise for the Heart is to bend down and help another up...
    Please Mark your Thread "Resolved", if the query is solved


    MyGear:
    ★ CPU ★ Ryzen 5 5800X
    ★ GPU ★ NVIDIA GeForce RTX 3080 TI Founder Edition
    ★ RAM ★ G. Skill Trident Z RGB 32GB 3600MHz
    ★ MB ★ ASUS TUF GAMING X570 (WI-FI) ATX Gaming
    ★ Storage ★ SSD SB-ROCKET-1TB + SEAGATE 2TB Barracuda IHD
    ★ Cooling ★ NOCTUA NH-D15 CHROMAX BLACK 140mm + 10 of Noctua NF-F12 PWM
    ★ PSU ★ ANTEC HCG-1000-EXTREME 1000 Watt 80 Plus Gold Fully Modular PSU
    ★ Case ★ LIAN LI PC-O11 DYNAMIC XL ROG (BLACK) (G99.O11DXL-X)
    ★ Monitor ★ LG Ultragear 27" 240Hz Gaming Monitor
    ★ Keyboard ★ TVS Electronics Gold Keyboard
    ★ Mouse ★ Logitech G502 Hero

  17. #17

    Thread Starter
    Addicted Member
    Join Date
    Feb 2009
    Location
    Bangalore India
    Posts
    201

    Arrow 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

  18. #18
    Discovering Life Siddharth Rout's Avatar
    Join Date
    Feb 2005
    Location
    Mumbai, India
    Posts
    12,001

    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:
    1. Private Sub CommandButton1_Click()
    2.     Dim oXLApp As Object
    3.  
    4.     '~~> Establish an EXCEL application object
    5.     On Error Resume Next
    6.     Set oXLApp = GetObject(, "Excel.Application")
    7.    
    8.     If Err.Number <> 0 Then
    9.         Set oXLApp = CreateObject("Excel.Application")
    10.         blnEXCEL = True
    11.     End If
    12.     Err.Clear
    13.     On Error GoTo 0
    14.    
    15.     '~~> Change the pathname and file as applicable
    16.     oXLApp.Workbooks.OpenText Filename:="C:\Tensile Test080909-145744.txt", _
    17.     Origin:=437, StartRow:=1, DataType:=xlDelimited, TextQualifier:= _
    18.     xlDoubleQuote, ConsecutiveDelimiter:=False, Tab:=False, Semicolon:=False _
    19.     , Comma:=True, Space:=False, Other:=False, FieldInfo:=Array(Array(1, 1), _
    20.     Array(2, 1), Array(3, 1)), TrailingMinusNumbers:=True
    21.    
    22.     oXLApp.Visible = True
    23. End Sub
    A good exercise for the Heart is to bend down and help another up...
    Please Mark your Thread "Resolved", if the query is solved


    MyGear:
    ★ CPU ★ Ryzen 5 5800X
    ★ GPU ★ NVIDIA GeForce RTX 3080 TI Founder Edition
    ★ RAM ★ G. Skill Trident Z RGB 32GB 3600MHz
    ★ MB ★ ASUS TUF GAMING X570 (WI-FI) ATX Gaming
    ★ Storage ★ SSD SB-ROCKET-1TB + SEAGATE 2TB Barracuda IHD
    ★ Cooling ★ NOCTUA NH-D15 CHROMAX BLACK 140mm + 10 of Noctua NF-F12 PWM
    ★ PSU ★ ANTEC HCG-1000-EXTREME 1000 Watt 80 Plus Gold Fully Modular PSU
    ★ Case ★ LIAN LI PC-O11 DYNAMIC XL ROG (BLACK) (G99.O11DXL-X)
    ★ Monitor ★ LG Ultragear 27" 240Hz Gaming Monitor
    ★ Keyboard ★ TVS Electronics Gold Keyboard
    ★ Mouse ★ Logitech G502 Hero

  19. #19

    Thread Starter
    Addicted Member
    Join Date
    Feb 2009
    Location
    Bangalore India
    Posts
    201

    Arrow Re: Late Binding In Case of Office

    Hi!
    Thaks a lot....
    im indebted to you....

    with regards!
    Sethuraman R

  20. #20
    Discovering Life Siddharth Rout's Avatar
    Join Date
    Feb 2005
    Location
    Mumbai, India
    Posts
    12,001

    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
    A good exercise for the Heart is to bend down and help another up...
    Please Mark your Thread "Resolved", if the query is solved


    MyGear:
    ★ CPU ★ Ryzen 5 5800X
    ★ GPU ★ NVIDIA GeForce RTX 3080 TI Founder Edition
    ★ RAM ★ G. Skill Trident Z RGB 32GB 3600MHz
    ★ MB ★ ASUS TUF GAMING X570 (WI-FI) ATX Gaming
    ★ Storage ★ SSD SB-ROCKET-1TB + SEAGATE 2TB Barracuda IHD
    ★ Cooling ★ NOCTUA NH-D15 CHROMAX BLACK 140mm + 10 of Noctua NF-F12 PWM
    ★ PSU ★ ANTEC HCG-1000-EXTREME 1000 Watt 80 Plus Gold Fully Modular PSU
    ★ Case ★ LIAN LI PC-O11 DYNAMIC XL ROG (BLACK) (G99.O11DXL-X)
    ★ Monitor ★ LG Ultragear 27" 240Hz Gaming Monitor
    ★ Keyboard ★ TVS Electronics Gold Keyboard
    ★ Mouse ★ Logitech G502 Hero

  21. #21

    Thread Starter
    Addicted Member
    Join Date
    Feb 2009
    Location
    Bangalore India
    Posts
    201

    Arrow 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

  22. #22
    Discovering Life Siddharth Rout's Avatar
    Join Date
    Feb 2005
    Location
    Mumbai, India
    Posts
    12,001

    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
    A good exercise for the Heart is to bend down and help another up...
    Please Mark your Thread "Resolved", if the query is solved


    MyGear:
    ★ CPU ★ Ryzen 5 5800X
    ★ GPU ★ NVIDIA GeForce RTX 3080 TI Founder Edition
    ★ RAM ★ G. Skill Trident Z RGB 32GB 3600MHz
    ★ MB ★ ASUS TUF GAMING X570 (WI-FI) ATX Gaming
    ★ Storage ★ SSD SB-ROCKET-1TB + SEAGATE 2TB Barracuda IHD
    ★ Cooling ★ NOCTUA NH-D15 CHROMAX BLACK 140mm + 10 of Noctua NF-F12 PWM
    ★ PSU ★ ANTEC HCG-1000-EXTREME 1000 Watt 80 Plus Gold Fully Modular PSU
    ★ Case ★ LIAN LI PC-O11 DYNAMIC XL ROG (BLACK) (G99.O11DXL-X)
    ★ Monitor ★ LG Ultragear 27" 240Hz Gaming Monitor
    ★ Keyboard ★ TVS Electronics Gold Keyboard
    ★ Mouse ★ Logitech G502 Hero

  23. #23

    Thread Starter
    Addicted Member
    Join Date
    Feb 2009
    Location
    Bangalore India
    Posts
    201

    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
    Attached Files Attached Files

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width