Can anyone see what's wrong with this code? 
Author Message
 Can anyone see what's wrong with this code?

It would be greatly appreciated.  I'm trying to run through the sheets
in an excel workbook, and edit the embedded word documents in each.
Each document has a bookmark Text1, that is currently not being found.
If I can manipulate this field, I'll be able to pass over a greater
amount of data to these 'reports' from excel with a little work.

Thanks in advance!  Code posted below.
Barrett

Sub Riskcont()

'dim the variable
 Dim MyWord As Word.Document
 Dim embeddedobject
 Dim sht

Dim sheetnames() As String
Dim sheetcount As Integer
Dim i As Integer

sheetcount = ActiveWorkbook.Sheets.Count
ReDim sheetnames(1 To sheetcount)

For i = 1 To sheetcount
    sheetnames(i) = ActiveWorkbook.Sheets(i).Name
Next i

For i = 1 To sheetcount
    Set sht = ActiveWorkbook.Sheets(sheetnames(i))
    For Each embeddedobject In sht.OLEObjects
        'loop through objects in sheet to make sure you have the word
document
        If embeddedobject.ProgId = "Word.Document.8" Then
                'Set the object varible
                Set MyWord = embeddedobject.Object
                MyWord.Select
                'Selection.Activate
                Selection.GoTo What:=wdGoToBookmark, Name:="Text1"
                Selection.TypeText Text:="01"
        End If
        Debug.Print MyWord.Name
        Debug.Print sht
    Next embeddedobject
Next i

Set MyWord = Nothing

End Sub



Sat, 08 Mar 2003 03:00:00 GMT  
 Can anyone see what's wrong with this code?
In ur using this code in asp then check this statement
Dim MyWord As Word.Document  (do not use type)

Dim MyWord
set MyWord = server.createobject("Word.Document ")


Quote:
> It would be greatly appreciated.  I'm trying to run through the sheets
> in an excel workbook, and edit the embedded word documents in each.
> Each document has a bookmark Text1, that is currently not being found.
> If I can manipulate this field, I'll be able to pass over a greater
> amount of data to these 'reports' from excel with a little work.

> Thanks in advance!  Code posted below.
> Barrett

> Sub Riskcont()

> 'dim the variable
>  Dim MyWord As Word.Document
>  Dim embeddedobject
>  Dim sht

> Dim sheetnames() As String
> Dim sheetcount As Integer
> Dim i As Integer

> sheetcount = ActiveWorkbook.Sheets.Count
> ReDim sheetnames(1 To sheetcount)

> For i = 1 To sheetcount
>     sheetnames(i) = ActiveWorkbook.Sheets(i).Name
> Next i

> For i = 1 To sheetcount
>     Set sht = ActiveWorkbook.Sheets(sheetnames(i))
>     For Each embeddedobject In sht.OLEObjects
>         'loop through objects in sheet to make sure you have the word
> document
>         If embeddedobject.ProgId = "Word.Document.8" Then
>                 'Set the object varible
>                 Set MyWord = embeddedobject.Object
>                 MyWord.Select
>                 'Selection.Activate
>                 Selection.GoTo What:=wdGoToBookmark, Name:="Text1"
>                 Selection.TypeText Text:="01"
>         End If
>         Debug.Print MyWord.Name
>         Debug.Print sht
>     Next embeddedobject
> Next i

> Set MyWord = Nothing

> End Sub



Sat, 08 Mar 2003 03:00:00 GMT  
 Can anyone see what's wrong with this code?
In ur using this code in asp then check this statement
Dim MyWord As Word.Document  (do not use type)

Dim MyWord
set MyWord = server.createobject("Word.Document ")


Quote:
> It would be greatly appreciated.  I'm trying to run through the sheets
> in an excel workbook, and edit the embedded word documents in each.
> Each document has a bookmark Text1, that is currently not being found.
> If I can manipulate this field, I'll be able to pass over a greater
> amount of data to these 'reports' from excel with a little work.

> Thanks in advance!  Code posted below.
> Barrett

> Sub Riskcont()

> 'dim the variable
>  Dim MyWord As Word.Document
>  Dim embeddedobject
>  Dim sht

> Dim sheetnames() As String
> Dim sheetcount As Integer
> Dim i As Integer

> sheetcount = ActiveWorkbook.Sheets.Count
> ReDim sheetnames(1 To sheetcount)

> For i = 1 To sheetcount
>     sheetnames(i) = ActiveWorkbook.Sheets(i).Name
> Next i

> For i = 1 To sheetcount
>     Set sht = ActiveWorkbook.Sheets(sheetnames(i))
>     For Each embeddedobject In sht.OLEObjects
>         'loop through objects in sheet to make sure you have the word
> document
>         If embeddedobject.ProgId = "Word.Document.8" Then
>                 'Set the object varible
>                 Set MyWord = embeddedobject.Object
>                 MyWord.Select
>                 'Selection.Activate
>                 Selection.GoTo What:=wdGoToBookmark, Name:="Text1"
>                 Selection.TypeText Text:="01"
>         End If
>         Debug.Print MyWord.Name
>         Debug.Print sht
>     Next embeddedobject
> Next i

> Set MyWord = Nothing

> End Sub



Sat, 08 Mar 2003 03:00:00 GMT  
 Can anyone see what's wrong with this code?
Thanks Sandeep!
Quote:

> In ur using this code in asp then check this statement
> Dim MyWord As Word.Document  (do not use type)

> Dim MyWord
> set MyWord = server.createobject("Word.Document ")



> > It would be greatly appreciated.  I'm trying to run through the sheets
> > in an excel workbook, and edit the embedded word documents in each.
> > Each document has a bookmark Text1, that is currently not being found.
> > If I can manipulate this field, I'll be able to pass over a greater
> > amount of data to these 'reports' from excel with a little work.

> > Thanks in advance!  Code posted below.
> > Barrett

> > Sub Riskcont()

> > 'dim the variable
> >  Dim MyWord As Word.Document
> >  Dim embeddedobject
> >  Dim sht

> > Dim sheetnames() As String
> > Dim sheetcount As Integer
> > Dim i As Integer

> > sheetcount = ActiveWorkbook.Sheets.Count
> > ReDim sheetnames(1 To sheetcount)

> > For i = 1 To sheetcount
> >     sheetnames(i) = ActiveWorkbook.Sheets(i).Name
> > Next i

> > For i = 1 To sheetcount
> >     Set sht = ActiveWorkbook.Sheets(sheetnames(i))
> >     For Each embeddedobject In sht.OLEObjects
> >         'loop through objects in sheet to make sure you have the word
> > document
> >         If embeddedobject.ProgId = "Word.Document.8" Then
> >                 'Set the object varible
> >                 Set MyWord = embeddedobject.Object
> >                 MyWord.Select
> >                 'Selection.Activate
> >                 Selection.GoTo What:=wdGoToBookmark, Name:="Text1"
> >                 Selection.TypeText Text:="01"
> >         End If
> >         Debug.Print MyWord.Name
> >         Debug.Print sht
> >     Next embeddedobject
> > Next i

> > Set MyWord = Nothing

> > End Sub



Sat, 08 Mar 2003 03:00:00 GMT  
 Can anyone see what's wrong with this code?

???

...
        If embeddedobject.ProgId = "Word.Document.8" Then
                'Set the object varible
                Set MyWord = embeddedobject.Object
                MyWord.Select
                'Selection.Activate
                MyWord.Selection.GoTo What:=wdGoToBookmark, Name:="Text1"
                MyWord.Selection.TypeText Text:="01"
        End If
...

or...

...
        If embeddedobject.ProgId = "Word.Document.8" Then
                With embeddedobject.Object
                  .Select
                  .Selection.GoTo What:=wdGoToBookmark, Name:="Text1"
                  .Selection.TypeText Text:="01"
                End With
        End If
...

--
Michael Harris
Microsoft.MVP.Scripting
--


Quote:
> It would be greatly appreciated.  I'm trying to run through the sheets
> in an excel workbook, and edit the embedded word documents in each.
> Each document has a bookmark Text1, that is currently not being found.
> If I can manipulate this field, I'll be able to pass over a greater
> amount of data to these 'reports' from excel with a little work.

> Thanks in advance!  Code posted below.
> Barrett

> Sub Riskcont()

> 'dim the variable
>  Dim MyWord As Word.Document
>  Dim embeddedobject
>  Dim sht

> Dim sheetnames() As String
> Dim sheetcount As Integer
> Dim i As Integer

> sheetcount = ActiveWorkbook.Sheets.Count
> ReDim sheetnames(1 To sheetcount)

> For i = 1 To sheetcount
>     sheetnames(i) = ActiveWorkbook.Sheets(i).Name
> Next i

> For i = 1 To sheetcount
>     Set sht = ActiveWorkbook.Sheets(sheetnames(i))
>     For Each embeddedobject In sht.OLEObjects
>         'loop through objects in sheet to make sure you have the word
> document
>         If embeddedobject.ProgId = "Word.Document.8" Then
>                 'Set the object varible
>                 Set MyWord = embeddedobject.Object
>                 MyWord.Select
>                 'Selection.Activate
>                 Selection.GoTo What:=wdGoToBookmark, Name:="Text1"
>                 Selection.TypeText Text:="01"
>         End If
>         Debug.Print MyWord.Name
>         Debug.Print sht
>     Next embeddedobject
> Next i

> Set MyWord = Nothing

> End Sub



Sat, 08 Mar 2003 03:00:00 GMT  
 
 [ 5 post ] 

 Relevant Pages 

1. Newbie: What's wrong with this code?

2. What's wrong with this source code?

3. What's wrong with this code?

4. What's wrong with my simple codes?

5. What's wrong with this code?

6. What's wrong with my VBScript code?

7. What's wrong with this code ?

8. What's wrong with my code???

9. What's wrong with my code???

10. What's wrong with this code?

11. What's wrong with this simple code??

12. what's wrong with this code

 

 
Powered by phpBB® Forum Software