+ Reply to Thread
Results 1 to 3 of 3

Run-time error '9': Subscript out of range

  1. #1
    Registered User
    Join Date
    12-21-2017
    Location
    Wokingham, England
    MS-Off Ver
    office 365 2013
    Posts
    46

    Run-time error '9': Subscript out of range

    I am trying to get the following code to work:
    <<
    Sub CallSetPropertyFunction()

    Dim PropertyName As String
    Dim PropertySet As PropertyLocation
    Dim PropertyValue As Variant
    Dim ContentLink As Boolean
    Dim TargetWorkBook As Workbook

    PropertyName = "Medical"
    PropertySet = PropertyLocationBoth
    PropertyValue = "Hospital"
    ContentLink = False

    Workbooks.Open ("N:\!DocumentDayFile\1SetPropertyTest.xlsx")

    Set TargetWorkBook = Workbooks("N:\!DocumentDayFile\1SetPropertyTest.xlsx")
    <<

    The line starting "Workbooks.Open..." works in that it opens the correct file thus proving that the file exists.

    The line starting "Set TargetWorkBook..." results in the above run time error.

    I am new to VBA programming but studies so far indicate that this error occurs when the target does not exist but the previous line opens the file successfully thus proving that it does.

    The ultimate project objective is to create custom file properties to scanned pdf files and office documents and set their values. This is just the first step.
    Any help would be appreciated.

  2. #2
    Forum Expert CK76's Avatar
    Join Date
    06-16-2015
    Location
    ONT, Canada
    MS-Off Ver
    Office 365 ProPlus
    Posts
    5,883

    Re: Run-time error '9': Subscript out of range

    You already opened the workbook. So you should just use file name instead of full path.
    i.e.
    Please Login or Register  to view this content.
    But you can do it in single line.
    Please Login or Register  to view this content.
    FYI - Please use code tag when posting VBA or other code. # button in the menu.
    ?Progress isn't made by early risers. It's made by lazy men trying to find easier ways to do something.?
    ― Robert A. Heinlein

  3. #3
    Registered User
    Join Date
    12-21-2017
    Location
    Wokingham, England
    MS-Off Ver
    office 365 2013
    Posts
    46

    Re: Run-time error '9': Subscript out of range

    Many thanks CK76 for your prompt reply and please accept my apologies for the dilatory response; I have been unwell.

    I thought I had already tried your suggestion but apparently not, either that or there was a typo in my original attempt. I did not realise however that I could do it in one line; most useful.

    This leads me to believe that the value of a workbook object can only be an open file name; is that correct?

+ Reply to Thread

Thread Information

Users Browsing this Thread

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

Similar Threads

  1. Run-time Error 9 , Subscript out of range..
    By kmmm in forum Excel Programming / VBA / Macros
    Replies: 5
    Last Post: 07-25-2017, 01:50 AM
  2. [SOLVED] run time error 9, subscript out of range.How to fix it?
    By ImranBhatti in forum Excel Programming / VBA / Macros
    Replies: 9
    Last Post: 10-20-2016, 03:34 PM
  3. Run time error '9': Subscript out of Range
    By mklindquist0815 in forum Excel Programming / VBA / Macros
    Replies: 7
    Last Post: 09-30-2016, 12:35 PM
  4. [SOLVED] Run Time Error : Subscript out of range 9
    By excel_126 in forum Excel Programming / VBA / Macros
    Replies: 12
    Last Post: 07-17-2014, 04:12 AM
  5. [SOLVED] Run-time error '9': subscript out of range - error occurs on multiple computers except one
    By BrettE in forum Excel Programming / VBA / Macros
    Replies: 7
    Last Post: 02-06-2014, 11:19 PM
  6. Run-time error '9': subscript out of range
    By nicko54 in forum Excel General
    Replies: 6
    Last Post: 02-02-2011, 09:08 PM
  7. Run-time error 9 subscript out of range
    By thebigman in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 04-01-2010, 05:00 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