Results 1 to 3 of 3

Can I declare a Variable as a Word document object? (Actually I did, but it didn't work!

Threaded View

  1. #1
    Forum Expert Doc.AElstein's Avatar
    Join Date
    05-23-2014
    Location
    '_- Germany >Outside Building things.... Mostly
    MS-Off Ver
    Office 2003 2007 2010 PC but Not mac. XP and Vista mostly, sometimes Win 7
    Posts
    3,618

    Can I declare a Variable as a Word document object? (Actually I did, but it didn't work!

    Hello
    It appears that there is a documents “collection” object of open documents. I appear to be able to refer to an open document via its item number ( Index ) or name, like
    Documents.Item("MyWordFile.docx")
    Or for short
    Documents("MyWordFile.docx")

    So I could, for example Activate that opened document with
    Documents("MyWordFile.docx").Activate

    I can do very similar to that in Excel VBA,
    or
    I can use a variable for my Workbook object like this:_..
    Dim Wb As Workbook
    _Set Wb = Workbooks("MyExcelFile.xlsx")
    _..then I can refer to the Workbook via that variable.
    So for example, having done that declaration I can do like:
    _Wb.Activate.


    I can’t seem to find any documentation on how to do something similar in Word VBA, pseudo like:
    Dim Doc As Document
    _Set Doc = Documents("MyWordFile.docx")

    Does anyone know if I can do that?

    Maybe this is all a bit of a different World to the VBA Excel one that I know about.
    or
    am I just a Dim Doc.?
    Thanks
    Alan

    P.s. What I actually want to do is determine the Active document at the start of a code in such a way that I can then safely refer to it later and not get mixed up if other documents start getting opened, etc.
    This would be one way, that seems to work: _..
    Dim DocNme As String
    _Let DocNme = ActiveDocument.Name
    _.. then later I can do like refer to that with
    _Documents.(DocNme)

    _.. I am puzzled that I cannot seem to refer to a Word document object as I can to an Excel Workbook object.
    Last edited by Doc.AElstein; 02-15-2017 at 03:26 PM. Reason: Reason for Editing: ??? - Well, I thought , "someone has to do it ! " :)
    '_- Google first, like this _ site:ExcelForum.com Gamut
    Use Code Tags: Highlight code; click on the # icon above,
    Post screenshots COPYABLE to a Spredsheet; NOT IMAGES PLEASE
    http://www.excelforum.com/the-water-...ml#post4109080
    https://app.box.com/s/gjpa8mk8ko4vkwcke3ig2w8z2wkfvrtv
    http://excelmatters.com/excel-forums/ ( Scrolll down to bottom )

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Similar Threads

  1. [SOLVED] Paste Excel object into Word document in landscape?
    By zijin_cheng in forum Excel General
    Replies: 4
    Last Post: 12-10-2014, 07:30 PM
  2. How can I get individual cells to work like a word document?
    By Jimbo0416 in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 05-12-2014, 07:54 AM
  3. [SOLVED] Set word variable to a document that’s already open
    By Trebor76 in forum Excel Programming / VBA / Macros
    Replies: 11
    Last Post: 11-23-2013, 06:01 PM
  4. how do I import variable data into a word document
    By GaryPick in forum Excel General
    Replies: 1
    Last Post: 03-30-2006, 10:55 AM
  5. [SOLVED] Variable as name of object does not work - Why?
    By -JEFF- in forum Excel Programming / VBA / Macros
    Replies: 7
    Last Post: 08-26-2005, 10:05 AM
  6. [SOLVED] How do you replace a work sheet in excel with a word document?
    By DonxCahill in forum Excel General
    Replies: 2
    Last Post: 07-11-2005, 12:05 PM
  7. [SOLVED] Assign a variable to a word document
    By Anson in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 01-06-2005, 05:06 PM

Bookmarks

Posting Permissions

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

Search Engine Friendly URLs by vBSEO 3.6.0 RC 1