Results 1 to 21 of 21

Thread: [RESOLVED] VB newbie needs help

  1. #1

    Thread Starter
    Member
    Join Date
    Mar 2006
    Posts
    32

    Resolved [RESOLVED] VB newbie needs help

    hi everyone!thanks for reading my thread hope that u can help me with VB

    ok the problem is like this.i have a word document that i would like to edit and save its content by using VB programming tools.th data in the word doc are like this

    p01=100
    p02=150
    p03=200

    and so on.so is there anyway for me to edit its value and at the same time save this edited version via VB programming tools that i wanna build?

    thanks!

  2. #2
    Ex-Super Mod RobDog888's Avatar
    Join Date
    Apr 2001
    Location
    LA, Calif. Raiders #1 AKA:Gangsta Yoda™
    Posts
    60,709

    Re: VB newbie needs help

    Welcome to the Forums.

    You are using what version of VB? VB6, VB.NET 2002/2003/2005/Express?

    VB/Office Guru™ (AKA: Gangsta Yoda®)
    I dont answer coding questions via PM. Please post a thread in the appropriate forum.

    Microsoft MVP 2006-2011
    Office Development FAQ (C#, VB.NET, VB 6, VBA)
    Senior Jedi Software Engineer MCP (VB 6 & .NET), BSEE, CET
    If a post has helped you then Please Rate it!
    Reps & Rating PostsVS.NET on Vista Multiple .NET Framework Versions Office Primary Interop AssembliesVB/Office Guru™ Word SpellChecker™.NETVB/Office Guru™ Word SpellChecker™ VB6VB.NET Attributes Ex.Outlook Global Address ListAPI Viewer utility.NET API Viewer Utility
    System: Intel i7 6850K, Geforce GTX1060, Samsung M.2 1 TB & SATA 500 GB, 32 GBs DDR4 3300 Quad Channel RAM, 2 Viewsonic 24" LCDs, Windows 10, Office 2016, VS 2019, VB6 SP6

  3. #3

    Thread Starter
    Member
    Join Date
    Mar 2006
    Posts
    32

    Re: VB newbie needs help

    oh sorry forgot to mention that

    im using vb 6

  4. #4
    Ex-Super Mod RobDog888's Avatar
    Join Date
    Apr 2001
    Location
    LA, Calif. Raiders #1 AKA:Gangsta Yoda™
    Posts
    60,709

    Re: VB newbie needs help

    Easiest way then is to record a macro doing your tasks and then stop recording, check the vba macro generated code in the VBA IDE (Alt_F11) and convert it into VB6.

    VB Code:
    1. Option explicit
    2. 'Add a reference to ms word xx.0 object library
    3. Private sub command1_click()
    4.     dim oApp as word.application
    5.     dim odoc as word.document
    6.     set oapp = new word.application
    7.     set odoc = oapp.documents.open("C:\mydoc.doc")
    8.     'Then convert the macro code and inser here.
    9.     'Should be using the .Find and Replace meth0ds
    10.  
    11.     odoc.save
    12.     odoc.close
    13.     set odoc = nothing
    14.     oapp.quit
    15.     set oapp = nothing
    16. end sub
    VB/Office Guru™ (AKA: Gangsta Yoda®)
    I dont answer coding questions via PM. Please post a thread in the appropriate forum.

    Microsoft MVP 2006-2011
    Office Development FAQ (C#, VB.NET, VB 6, VBA)
    Senior Jedi Software Engineer MCP (VB 6 & .NET), BSEE, CET
    If a post has helped you then Please Rate it!
    Reps & Rating PostsVS.NET on Vista Multiple .NET Framework Versions Office Primary Interop AssembliesVB/Office Guru™ Word SpellChecker™.NETVB/Office Guru™ Word SpellChecker™ VB6VB.NET Attributes Ex.Outlook Global Address ListAPI Viewer utility.NET API Viewer Utility
    System: Intel i7 6850K, Geforce GTX1060, Samsung M.2 1 TB & SATA 500 GB, 32 GBs DDR4 3300 Quad Channel RAM, 2 Viewsonic 24" LCDs, Windows 10, Office 2016, VS 2019, VB6 SP6

  5. #5

    Thread Starter
    Member
    Join Date
    Mar 2006
    Posts
    32

    Re: VB newbie needs help

    thanks ROb for the reply!really appreciate it.
    but since i'm so very new at this (VB that is) so i don't quite understand the way that you proposed (the macro).
    the pics below is the way i wanted to do


    referring to the figure, i want to edit a text or excel files inside VB programming.i should be able to open the file via VB as in the pics, edit it there and save it back into the folder.i really hope could do it like that but have no idea how to do it.i'm thinking of using OLE but didn't know how.please help!

    thanks!

  6. #6
    Ex-Super Mod RobDog888's Avatar
    Join Date
    Apr 2001
    Location
    LA, Calif. Raiders #1 AKA:Gangsta Yoda™
    Posts
    60,709

    Re: VB newbie needs help

    The Save button will be like the code example I already posted. the New button will be similar but with this line - set odoc = oapp.documents.add.

    VB/Office Guru™ (AKA: Gangsta Yoda®)
    I dont answer coding questions via PM. Please post a thread in the appropriate forum.

    Microsoft MVP 2006-2011
    Office Development FAQ (C#, VB.NET, VB 6, VBA)
    Senior Jedi Software Engineer MCP (VB 6 & .NET), BSEE, CET
    If a post has helped you then Please Rate it!
    Reps & Rating PostsVS.NET on Vista Multiple .NET Framework Versions Office Primary Interop AssembliesVB/Office Guru™ Word SpellChecker™.NETVB/Office Guru™ Word SpellChecker™ VB6VB.NET Attributes Ex.Outlook Global Address ListAPI Viewer utility.NET API Viewer Utility
    System: Intel i7 6850K, Geforce GTX1060, Samsung M.2 1 TB & SATA 500 GB, 32 GBs DDR4 3300 Quad Channel RAM, 2 Viewsonic 24" LCDs, Windows 10, Office 2016, VS 2019, VB6 SP6

  7. #7

    Thread Starter
    Member
    Join Date
    Mar 2006
    Posts
    32

    Re: VB newbie needs help

    Option Explicit

    Private Sub cmdNew_Click()
    OLE1.CreateEmbed "", "Word.Document"
    OLE1.DoVerb vbOLEUIActivate
    OLE1.SizeMode = 1
    With OLE1.object
    .ActiveWindow.DisplayVerticalScrollbar = True
    .ActiveWindow.DisplayHorizontalScrollbar = True
    End With
    End Sub
    ____________________________________________________________
    so i have learn to open a new word doc in OLE window.but i want to open a document not create new one.Can you direct me how to do it?
    ____________________________________________________________
    Private Sub mnuSaveAs_Click()
    'Display the Save As Dialog Box

    dlgCommon.ShowSave 'Display the Save As dialog box
    End Sub
    Private Sub mnuOpen_Click()
    'Display the Open Dialog Box

    dlgCommon.ShowOpen 'Display the Open dialog box
    End Sub
    _____________________________________________________________
    referring to common dialog box tutorial, i found out that this command will open the dialog bo but how to use it to open a word document inside the OLE window then using the save as button to save the document after i've finish editing it?

    thanks!

  8. #8
    Ex-Super Mod RobDog888's Avatar
    Join Date
    Apr 2001
    Location
    LA, Calif. Raiders #1 AKA:Gangsta Yoda™
    Posts
    60,709

    Re: VB newbie needs help

    Heres an example of creating a linked ole object on an existing word document.
    VB Code:
    1. Private Sub cmdOpen_Click()
    2.     dlgCommon.ShowOpen
    3.     OLE1.CreateLink dlgCommon.FileName, "Word.Document"
    4.     OLE1.DoVerb vbOLEOpen
    5. End Sub
    Once the linked document is linked you can coninue to open it or double click on the ole control to invoke the verb open command.
    VB/Office Guru™ (AKA: Gangsta Yoda®)
    I dont answer coding questions via PM. Please post a thread in the appropriate forum.

    Microsoft MVP 2006-2011
    Office Development FAQ (C#, VB.NET, VB 6, VBA)
    Senior Jedi Software Engineer MCP (VB 6 & .NET), BSEE, CET
    If a post has helped you then Please Rate it!
    Reps & Rating PostsVS.NET on Vista Multiple .NET Framework Versions Office Primary Interop AssembliesVB/Office Guru™ Word SpellChecker™.NETVB/Office Guru™ Word SpellChecker™ VB6VB.NET Attributes Ex.Outlook Global Address ListAPI Viewer utility.NET API Viewer Utility
    System: Intel i7 6850K, Geforce GTX1060, Samsung M.2 1 TB & SATA 500 GB, 32 GBs DDR4 3300 Quad Channel RAM, 2 Viewsonic 24" LCDs, Windows 10, Office 2016, VS 2019, VB6 SP6

  9. #9

    Thread Starter
    Member
    Join Date
    Mar 2006
    Posts
    32

    Re: VB newbie needs help

    ok i do what you've said but that only lets me to open microsoft word when i click "open".is there any way to open the document inside the OLE frame,(in other words it will not run microsoft word but open the document inside vb itself) the i can edit it inside the OLE window?

    thanks!

  10. #10
    Ex-Super Mod RobDog888's Avatar
    Join Date
    Apr 2001
    Location
    LA, Calif. Raiders #1 AKA:Gangsta Yoda™
    Posts
    60,709

    Re: VB newbie needs help

    Probably change it to .CreateEmbed
    VB/Office Guru™ (AKA: Gangsta Yoda®)
    I dont answer coding questions via PM. Please post a thread in the appropriate forum.

    Microsoft MVP 2006-2011
    Office Development FAQ (C#, VB.NET, VB 6, VBA)
    Senior Jedi Software Engineer MCP (VB 6 & .NET), BSEE, CET
    If a post has helped you then Please Rate it!
    Reps & Rating PostsVS.NET on Vista Multiple .NET Framework Versions Office Primary Interop AssembliesVB/Office Guru™ Word SpellChecker™.NETVB/Office Guru™ Word SpellChecker™ VB6VB.NET Attributes Ex.Outlook Global Address ListAPI Viewer utility.NET API Viewer Utility
    System: Intel i7 6850K, Geforce GTX1060, Samsung M.2 1 TB & SATA 500 GB, 32 GBs DDR4 3300 Quad Channel RAM, 2 Viewsonic 24" LCDs, Windows 10, Office 2016, VS 2019, VB6 SP6

  11. #11

    Thread Starter
    Member
    Join Date
    Mar 2006
    Posts
    32

    Re: VB newbie needs help

    change the OLE1.CreateLink to OLE1.CreateEmbed ?

  12. #12
    Ex-Super Mod RobDog888's Avatar
    Join Date
    Apr 2001
    Location
    LA, Calif. Raiders #1 AKA:Gangsta Yoda™
    Posts
    60,709

    Re: VB newbie needs help

    Did you try it?
    VB/Office Guru™ (AKA: Gangsta Yoda®)
    I dont answer coding questions via PM. Please post a thread in the appropriate forum.

    Microsoft MVP 2006-2011
    Office Development FAQ (C#, VB.NET, VB 6, VBA)
    Senior Jedi Software Engineer MCP (VB 6 & .NET), BSEE, CET
    If a post has helped you then Please Rate it!
    Reps & Rating PostsVS.NET on Vista Multiple .NET Framework Versions Office Primary Interop AssembliesVB/Office Guru™ Word SpellChecker™.NETVB/Office Guru™ Word SpellChecker™ VB6VB.NET Attributes Ex.Outlook Global Address ListAPI Viewer utility.NET API Viewer Utility
    System: Intel i7 6850K, Geforce GTX1060, Samsung M.2 1 TB & SATA 500 GB, 32 GBs DDR4 3300 Quad Channel RAM, 2 Viewsonic 24" LCDs, Windows 10, Office 2016, VS 2019, VB6 SP6

  13. #13

    Thread Starter
    Member
    Join Date
    Mar 2006
    Posts
    32

    Re: VB newbie needs help

    yep i did try it but but it said run time error '424'

  14. #14
    Ex-Super Mod RobDog888's Avatar
    Join Date
    Apr 2001
    Location
    LA, Calif. Raiders #1 AKA:Gangsta Yoda™
    Posts
    60,709

    Re: VB newbie needs help

    Hmm, try this.
    VB Code:
    1. Option Explicit
    2.  
    3. Private Sub Form_Load()
    4.     OLE1.CreateEmbed "D:\Test.doc", "Word.Application"
    5.     OLE1.OLETypeAllowed = vbOLEEither
    6.     OLE1.SizeMode = 0
    7.     OLE1.DisplayType = 0
    8.     OLE1.UpdateOptions = 0
    9. End Sub
    VB/Office Guru™ (AKA: Gangsta Yoda®)
    I dont answer coding questions via PM. Please post a thread in the appropriate forum.

    Microsoft MVP 2006-2011
    Office Development FAQ (C#, VB.NET, VB 6, VBA)
    Senior Jedi Software Engineer MCP (VB 6 & .NET), BSEE, CET
    If a post has helped you then Please Rate it!
    Reps & Rating PostsVS.NET on Vista Multiple .NET Framework Versions Office Primary Interop AssembliesVB/Office Guru™ Word SpellChecker™.NETVB/Office Guru™ Word SpellChecker™ VB6VB.NET Attributes Ex.Outlook Global Address ListAPI Viewer utility.NET API Viewer Utility
    System: Intel i7 6850K, Geforce GTX1060, Samsung M.2 1 TB & SATA 500 GB, 32 GBs DDR4 3300 Quad Channel RAM, 2 Viewsonic 24" LCDs, Windows 10, Office 2016, VS 2019, VB6 SP6

  15. #15

    Thread Starter
    Member
    Join Date
    Mar 2006
    Posts
    32

    Re: VB newbie needs help

    hmm now its compile error variarble not defined

    hey rob how bout opening excel but still like the way i asked you?is it easier?since word doesn't really suit to be a database anyway so how's excel?

    thanks!

  16. #16
    Ex-Super Mod RobDog888's Avatar
    Join Date
    Apr 2001
    Location
    LA, Calif. Raiders #1 AKA:Gangsta Yoda™
    Posts
    60,709

    Re: VB newbie needs help

    Not sure why you are having these issues. Do you have service pack 6 for VB or VS installed too?

    To use Excel just change the class type to "Excel.Application"

    OLE1.CreateEmbed "D:\Test.xls", "Excel.Application"
    VB/Office Guru™ (AKA: Gangsta Yoda®)
    I dont answer coding questions via PM. Please post a thread in the appropriate forum.

    Microsoft MVP 2006-2011
    Office Development FAQ (C#, VB.NET, VB 6, VBA)
    Senior Jedi Software Engineer MCP (VB 6 & .NET), BSEE, CET
    If a post has helped you then Please Rate it!
    Reps & Rating PostsVS.NET on Vista Multiple .NET Framework Versions Office Primary Interop AssembliesVB/Office Guru™ Word SpellChecker™.NETVB/Office Guru™ Word SpellChecker™ VB6VB.NET Attributes Ex.Outlook Global Address ListAPI Viewer utility.NET API Viewer Utility
    System: Intel i7 6850K, Geforce GTX1060, Samsung M.2 1 TB & SATA 500 GB, 32 GBs DDR4 3300 Quad Channel RAM, 2 Viewsonic 24" LCDs, Windows 10, Office 2016, VS 2019, VB6 SP6

  17. #17

    Thread Starter
    Member
    Join Date
    Mar 2006
    Posts
    32

    Re: VB newbie needs help

    okay ill try it first

    one more thing do i have to put a OLE (excel) window on the form?

  18. #18
    Ex-Super Mod RobDog888's Avatar
    Join Date
    Apr 2001
    Location
    LA, Calif. Raiders #1 AKA:Gangsta Yoda™
    Posts
    60,709

    Re: VB newbie needs help

    Absolutely or else your not using it.
    VB/Office Guru™ (AKA: Gangsta Yoda®)
    I dont answer coding questions via PM. Please post a thread in the appropriate forum.

    Microsoft MVP 2006-2011
    Office Development FAQ (C#, VB.NET, VB 6, VBA)
    Senior Jedi Software Engineer MCP (VB 6 & .NET), BSEE, CET
    If a post has helped you then Please Rate it!
    Reps & Rating PostsVS.NET on Vista Multiple .NET Framework Versions Office Primary Interop AssembliesVB/Office Guru™ Word SpellChecker™.NETVB/Office Guru™ Word SpellChecker™ VB6VB.NET Attributes Ex.Outlook Global Address ListAPI Viewer utility.NET API Viewer Utility
    System: Intel i7 6850K, Geforce GTX1060, Samsung M.2 1 TB & SATA 500 GB, 32 GBs DDR4 3300 Quad Channel RAM, 2 Viewsonic 24" LCDs, Windows 10, Office 2016, VS 2019, VB6 SP6

  19. #19

    Thread Starter
    Member
    Join Date
    Mar 2006
    Posts
    32

    Re: VB newbie needs help

    hey rob do you know how to browse pics in vb and save it in a database?i know browse using common control but i cant open it in vb.And how do i open a unigraphics drawing file via vb?to automatically run unigraphics of course (unigraphics is a CAD software)
    Last edited by posto; Apr 1st, 2006 at 11:43 PM.

  20. #20
    Ex-Super Mod RobDog888's Avatar
    Join Date
    Apr 2001
    Location
    LA, Calif. Raiders #1 AKA:Gangsta Yoda™
    Posts
    60,709

    Re: VB newbie needs help

    Probably would be better to start a new thread on this.

    Dont forget to mention which db your using and version etc.
    VB/Office Guru™ (AKA: Gangsta Yoda®)
    I dont answer coding questions via PM. Please post a thread in the appropriate forum.

    Microsoft MVP 2006-2011
    Office Development FAQ (C#, VB.NET, VB 6, VBA)
    Senior Jedi Software Engineer MCP (VB 6 & .NET), BSEE, CET
    If a post has helped you then Please Rate it!
    Reps & Rating PostsVS.NET on Vista Multiple .NET Framework Versions Office Primary Interop AssembliesVB/Office Guru™ Word SpellChecker™.NETVB/Office Guru™ Word SpellChecker™ VB6VB.NET Attributes Ex.Outlook Global Address ListAPI Viewer utility.NET API Viewer Utility
    System: Intel i7 6850K, Geforce GTX1060, Samsung M.2 1 TB & SATA 500 GB, 32 GBs DDR4 3300 Quad Channel RAM, 2 Viewsonic 24" LCDs, Windows 10, Office 2016, VS 2019, VB6 SP6

  21. #21

    Thread Starter
    Member
    Join Date
    Mar 2006
    Posts
    32

    Re: VB newbie needs help

    ok! thanks for your help rob!

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