Results 1 to 4 of 4

Thread: Basic macro questions

  1. #1

    Thread Starter
    New Member
    Join Date
    Oct 2006
    Posts
    4

    Basic macro questions

    I just started with Office development (I need to do a job within a week or something like that). Basically, what I want to do is to make a macro in word(with VBA script). The macro will consist of a form where the user can type some values. These values should then be inserted at various positions in a document-template and some lines are to be drawn. So, my questions is:

    Can I make a makro that opens a template and edit it? (without having to open the template before running the macro)

    How can I decide exactly where I want to put the text? I know how to move the selection but that depends on where the cursor was right? I want to set an absolute position.

  2. #2
    Don't Panic! Ecniv's Avatar
    Join Date
    Nov 2000
    Location
    Amsterdam...
    Posts
    5,343

    Re: Basic macro questions

    Can I make a makro that opens a template and edit it? (without having to open the template before running the macro)
    Yup. Check the intellisense/help on Documents.Open or Documents.Add methods.


    How can I decide exactly where I want to put the text? I know how to move the selection but that depends on where the cursor was right? I want to set an absolute position.
    Word works like Excel using ranges. Only Words ranges are characters from the start of the doc (or section or table/paragraph etc).
    You could use a find and replace, putting in (for example) '(token01)' (without single quotes) to find an then your code can replace with whatever is typed in. Or you can store specific position(s) in the doc to add to. Or you can find a bookmark and add after that.

    Easiest is to record a macro of what you want, then change the code as you need. Especially on the objects used (ie try to stay away from the selection object).

    BOFH Now, BOFH Past, Information on duplicates

    Feeling like a fly on the inside of a closed window (Thunk!)
    If I post a lot, it is because I am bored at work! ;D Or stuck...
    * Anything I post can be only my opinion. Advice etc is up to you to persue...

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

    Re: Basic macro questions

    Welcome to the Forums.

    You will need a document or template document that consists of this UserForm.

    You can create a new document off off of it or another template and in this document/template you would have bookmarks where you need to insert your text from the UserForm.

    For help on recording a macro see my FAQ - http://vbforums.com/showthread.php?t=402032

    This will help you see how word codes the actions you desire.
    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

  4. #4

    Thread Starter
    New Member
    Join Date
    Oct 2006
    Posts
    4

    Re: Basic macro questions

    Thanks. How can I avoid using the Selection object (when I record a macro, that object is used). Right now Im using bookmarks. But how can I store a certain position (I would really like to store a position and draw a line from that)

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