+ Reply to Thread
Results 1 to 6 of 6

help with my code please. (Error: Object doesn't support this property or method)

Hybrid View

funkymonkUK help with my code please.... 04-06-2006, 04:54 AM
Guest Re: help with my code please.... 04-06-2006, 05:35 AM
funkymonkUK yes i want this automated. ... 04-06-2006, 05:57 AM
Guest Re: help with my code please.... 04-06-2006, 06:20 AM
funkymonkUK i tried that with still no... 04-06-2006, 10:01 AM
Guest Re: help with my code please.... 04-06-2006, 10:50 AM
  1. #1
    Forum Contributor funkymonkUK's Avatar
    Join Date
    01-07-2005
    Location
    London, England
    Posts
    500

    help with my code please. (Error: Object doesn't support this property or method)

    HI

    i got a piece of code that runs from excel it opens a word document updates parts of the document then breaks the links between Word and Excel and then saves it.

    I now want to add a table of contents page to the word document. I have set up the page that I what it to do. I recorded the code and got the following.
    Sub InsertTOC()



    ' There is a bookmark called "TOC" this line goes to this part of the document

    Selection.Goto What:=wdGoToBookmark, Name:="TOC"
    With ActiveDocument.Bookmarks
    .DefaultSorting = wdSortByName
    .ShowHidden = False
    End With
    'Then it move to the right of it and then moves down a couple of lines
    Selection.MoveRight Unit:=wdCharacter, Count:=1
    Selection.TypeParagraph
    Selection.TypeParagraph
    Selection.TypeParagraph
    Selection.ParagraphFormat.Alignment = wdAlignParagraphLeft
    ' Insert fields (TOC) onto the page
    Selection.Fields.Add Range:=Selection.Range, Type:=wdFieldEmpty, Text:= _
    "TOC ", PreserveFormatting:=True
    End Sub


    I copied the code and put it into my Excel VBA and ran it it comes with Object doesn't support this property or method and highlights the first line.

    any ideas to get this to word?

  2. #2
    RB Smissaert
    Guest

    Re: help with my code please. (Error: Object doesn't support this property or method)

    As you are doing wdGoToBookmark etc. I take it you doing this with
    automation
    and a reference to Word.
    In your code thought I don't see any automation code such as
    Dim oWord as Word.Application etc.
    Not sure what you are trying to do.

    RBS

    "funkymonkUK" <funkymonkUK.25u4ho_1144313703.1868@excelforum-nospam.com>
    wrote in message
    news:funkymonkUK.25u4ho_1144313703.1868@excelforum-nospam.com...
    >
    > HI
    >
    > i got a piece of code that runs from excel it opens a word document
    > updates parts of the document then breaks the links between Word and
    > Excel and then saves it.
    >
    > I now want to add a table of contents page to the word document. I have
    > set up the page that I what it to do. I recorded the code and got the
    > following.
    > Sub InsertTOC()
    >
    >
    >
    > ' There is a bookmark called "TOC" this line goes to this part of the
    > document
    >
    > Selection.Goto What:=wdGoToBookmark, Name:="TOC"
    > With ActiveDocument.Bookmarks
    > DefaultSorting = wdSortByName
    > ShowHidden = False
    > End With
    > 'Then it move to the right of it and then moves down a couple of lines
    > Selection.MoveRight Unit:=wdCharacter, Count:=1
    > Selection.TypeParagraph
    > Selection.TypeParagraph
    > Selection.TypeParagraph
    > Selection.ParagraphFormat.Alignment = wdAlignParagraphLeft
    > ' Insert fields (TOC) onto the page
    > Selection.Fields.Add Range:=Selection.Range, Type:=wdFieldEmpty, Text:=
    > _
    > "TOC ", PreserveFormatting:=True
    > End Sub
    >
    >
    > I copied the code and put it into my Excel VBA and ran it it comes with
    > Object doesn't support this property or method and highlights the first
    > line.
    >
    > any ideas to get this to word?
    >
    >
    > --
    > funkymonkUK
    > ------------------------------------------------------------------------
    > funkymonkUK's Profile:
    > http://www.excelforum.com/member.php...o&userid=18135
    > View this thread: http://www.excelforum.com/showthread...hreadid=530410
    >



  3. #3
    Forum Contributor funkymonkUK's Avatar
    Join Date
    01-07-2005
    Location
    London, England
    Posts
    500
    yes i want this automated.

    Sorry in my main sub I got the following


    Option Explicit

    Sub runReports()
    Dim wrdapp As Word.Application
    Dim wrddoc As Word.Document
    Dim rng As Word.Range
    Dim cel As Object
    Dim sheet As Worksheet
    Dim counter As Integer
    Dim starting As String

    ' code to open up word let the document update then break the links
    ' the next part opens the headers and footers in the word document and
    ' breaks the links. Read on below to see the DIM's
    doHeadFoot

    ' then my code to insert Table of contents which I have already posted

    insertTOC
    End sub

    Sub doHeadFoot()
    Dim oField As Field
    Dim oSection As Section
    Dim oHeader As HeaderFooter
    Dim oFooter As HeaderFooter



    Do i have to declare word again as my hearder and footer code works 100%?

  4. #4
    RB Smissaert
    Guest

    Re: help with my code please. (Error: Object doesn't support this property or method)

    I don't think you will have to declare the Word application again, but you
    must do something like:

    with wrddoc
    ..Selection .Goto What

    etc. where wrddoc has to be the particular Word document.

    As the way it is now Selection applies to Excel.

    RBS

    "funkymonkUK" <funkymonkUK.25u7hz_1144317602.7758@excelforum-nospam.com>
    wrote in message
    news:funkymonkUK.25u7hz_1144317602.7758@excelforum-nospam.com...
    >
    > yes i want this automated.
    >
    > Sorry in my main sub I got the following
    >
    >
    > Option Explicit
    >
    > Sub runReports()
    > Dim wrdapp As Word.Application
    > Dim wrddoc As Word.Document
    > Dim rng As Word.Range
    > Dim cel As Object
    > Dim sheet As Worksheet
    > Dim counter As Integer
    > Dim starting As String
    >
    > ' code to open up word let the document update then break the links
    > ' the next part opens the headers and footers in the word document and
    > ' breaks the links. Read on below to see the DIM's
    > doHeadFoot
    >
    > ' then my code to insert Table of contents which I have already posted
    >
    > insertTOC
    > End sub
    >
    > Sub doHeadFoot()
    > Dim oField As Field
    > Dim oSection As Section
    > Dim oHeader As HeaderFooter
    > Dim oFooter As HeaderFooter
    >
    >
    >
    > Do i have to declare word again as my hearder and footer code works
    > 100%?
    >
    >
    > --
    > funkymonkUK
    > ------------------------------------------------------------------------
    > funkymonkUK's Profile:
    > http://www.excelforum.com/member.php...o&userid=18135
    > View this thread: http://www.excelforum.com/showthread...hreadid=530410
    >



  5. #5
    Forum Contributor funkymonkUK's Avatar
    Join Date
    01-07-2005
    Location
    London, England
    Posts
    500
    i tried that with still no luck

  6. #6
    RB Smissaert
    Guest

    Re: help with my code please. (Error: Object doesn't support this property or method)

    Maybe you should post all the relevant code.

    RBS

    "funkymonkUK" <funkymonkUK.25uj2n_1144332607.9822@excelforum-nospam.com>
    wrote in message
    news:funkymonkUK.25uj2n_1144332607.9822@excelforum-nospam.com...
    >
    > i tried that with still no luck
    >
    >
    > --
    > funkymonkUK
    > ------------------------------------------------------------------------
    > funkymonkUK's Profile:
    > http://www.excelforum.com/member.php...o&userid=18135
    > View this thread: http://www.excelforum.com/showthread...hreadid=530410
    >



+ Reply to Thread

Thread Information

Users Browsing this Thread

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

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