VBA error, quick help please

Armster

Board Regular
Joined
Jul 26, 2007
Messages
63
Ok I have the following code, but I can't work out why it doesn't like the

set CoDoc = Sheets("EntryForm").Range(irow, 5)

every time I get to here i have the following error

application-defined or object defined erro - Run-time error '1004'

overview of the macro:

picks up site information and codes, fills it into relevant standard word forms, prints these off, saves it, and then goes to the next company form in the list and repeats.

Code:
Sub Word1()
 
    Dim WordApp As Object
    Dim Data As Range, SiteID As String
    Dim CoDocument As String
    Dim Company As String
    Dim Records As Integer, i As Integer
    Dim Region As String, SalesAmt As String, SalesNum As String
    Dim SaveAsName As String
    Dim TodayDate As String
    Dim Author As String
    Dim Value As String
    Dim irow As Integer
    
       

' <<<< LOOP SETUP >>>>
irow = 5
While Not IsEmpty(Cells(irow, 1))

    
' Opens an instance of MS Word and then opens the document Below to be confirgured

        Set Data = Sheets("EntryForm").Range("A1")
            SiteName = Sheets("EntryForm").Range("B1")
            SiteID = Sheets("EntryForm").Range("B2")
            Value = Sheets("EntryForm").Range("B3")
            TodayDate = Format(Date, "mmmm d, yyyy")
            CoDoc = Sheets("EntryForm").Range(irow, 5)
            Company = Sheets("EntryForm").Range(irow, 1)
            Author = "David Armstrong"
            SaveAsName = ThisWorkbook.Path & "\" & SiteName & " - " & Company & ".doc"

'  <<<<<<<<<<<<<<START OF LOOP>>>>>>>>>>>>>>>>>>>>>
    
     
    
    ActiveWindow.Visible = False
    Windows("Form test.xls").Activate
    Set WordApp = CreateObject("Word.Application")
    WordApp.Visible = True
    
'TBA  EDIT THIS for release version
WDoc = ThisWorkbook.Path & "\" & CoDoc & ".doc"
    WordApp.Documents.Open WDoc
  
    '  Paste from Excel Variables into Words Bookmarks
  
With WordApp
If .ActiveDocument.Bookmarks.Exists("Sitetext") Then
    .ActiveDocument.Bookmarks("Sitetext").Range.Text = SiteName
End If

If .ActiveDocument.Bookmarks.Exists("reftext") Then
    .ActiveDocument.Bookmarks("reftext").Range.Text = SiteID
End If

If .ActiveDocument.Bookmarks.Exists("createdate") Then
.ActiveDocument.Bookmarks("createdate").Range.Text = TodayDate
End If

If .ActiveDocument.Bookmarks.Exists("value") Then
    .ActiveDocument.Bookmarks("value").Range.Text = SiteID
End If

If .ActiveDocument.Bookmarks.Exists("authortext") Then
    .ActiveDocument.Bookmarks("authortext").Range.Text = SiteID
End If
    
    
    
   .ActiveDocument.SaveAs Filename:=SaveAsName

        
' Print and close
        .ActiveDocument.PrintOut
        .ActiveDocument.Quit
End With


    Set WordDoc = Nothing
    Set WordApp = Nothing
    
    
 
 
    Range(irow, 3).Select
    ActiveCell.FormulaR1C1 = TodayDate
    irow = irow + 1
    
  Wend
' <<<<<<<<<<<<<<<End of loop>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
    
    
    
End Sub
 

Excel Facts

What did Pito Salas invent?
Pito Salas, working for Lotus, popularized what would become to be pivot tables. It was released as Lotus Improv in 1989.
Instead of Range try using Cells.
 
Upvote 0
Thanks that worked :) knew it was something simple :)

maybe a tougher question for you though.......

Can you script a macro so it creates a checkbox at a certain cell so when the macro runs down it can put a check box next to the relevant company in the list (a feature my director wants)
 
Upvote 0
Why would you/your director want that?

Sure you can programatically create controls like checkboxes, but I would probably say why?

What's the intended purpose?
 
Upvote 0
Never Mind,

i worked it out :)

Code:
    ActiveSheet.CheckBoxes.Add(Cells(irow, 2).Left, Cells(irow, 2).Top, 10, 10).Select
        With Selection
        .Placement = xlMove
        .PrintObject = True
        .Value = xlOn
        .Characters.Text = "Form Printed"
        .ShapeRange.Width = 150
        End With

Thanks though
 
Upvote 0

Forum statistics

Threads
1,214,386
Messages
6,119,220
Members
448,876
Latest member
Solitario

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top