Sub or function not defined, running word code from excel..

Chrisjd2

Board Regular
Joined
Mar 1, 2016
Messages
61
Hi Chaps,

I'm exporting some data into word from excel, and it gives me this error:- "Sub or Function, Not defined"

Code:
Set objWord = CreateObject("Word.Application")Set objDoc = objWord.Documents.Add
objWord.Visible = True
    
    With objDoc.PageSetup
        .LineNumbering.Active = False
        .Orientation = wdOrientPortrait
        .TopMargin = CentimetersToPoints(2.54)
        .BottomMargin = CentimetersToPoints(2.54)
        .LeftMargin = CentimetersToPoints(2.54)
        .RightMargin = CentimetersToPoints(2.54)
        .Gutter = CentimetersToPoints(0)
        .HeaderDistance = CentimetersToPoints(1.25)
        .FooterDistance = CentimetersToPoints(1.25)
        .PageWidth = CentimetersToPoints(16.2)
        .PageHeight = CentimetersToPoints(22.9)
        .FirstPageTray = wdPrinterDefaultBin
        .OtherPagesTray = wdPrinterDefaultBin
        .SectionStart = wdSectionNewPage
        .OddAndEvenPagesHeaderFooter = False
        .DifferentFirstPageHeaderFooter = False
        .VerticalAlignment = wdAlignVerticalTop
        .SuppressEndnotes = False
        .MirrorMargins = False
        .TwoPagesOnOne = False
        .BookFoldPrinting = False
        .BookFoldRevPrinting = False
        .BookFoldPrintingSheets = 1
        .GutterPos = wdGutterPosLeft
    End With
 

Excel Facts

Can you AutoAverage in Excel?
There is a drop-down next to the AutoSum symbol. Open the drop-down to choose AVERAGE, COUNT, MAX, or MIN
Hi, this compiles..:

Rich (BB code):
Const wdOrientPortrait As Long = 0
Const wdPrinterDefaultBin As Long = 0
Const wdSectionNewPage As Long = 2
Const wdAlignVerticalTop As Long = 0
Const wdGutterPosLeft As Long = 0<o:p></o:p>
Set objWord =CreateObject("Word.Application")
Set objDoc = objWord.Documents.Add<o:p></o:p>
objWord.Visible = True
  
    With objDoc.PageSetup
        .LineNumbering.Active = False
        .Orientation = wdOrientPortrait
        .TopMargin = Application.CentimetersToPoints(2.54)
        .BottomMargin = Application.CentimetersToPoints(2.54)
        .LeftMargin = Application.CentimetersToPoints(2.54)
        .RightMargin = Application.CentimetersToPoints(2.54)
        .Gutter = Application.CentimetersToPoints(0)
        .HeaderDistance = Application.CentimetersToPoints(1.25)
        .FooterDistance = Application.CentimetersToPoints(1.25)
        .PageWidth = Application.CentimetersToPoints(16.2)
        .PageHeight = Application.CentimetersToPoints(22.9)
        .FirstPageTray = wdPrinterDefaultBin
        .OtherPagesTray = wdPrinterDefaultBin
        .SectionStart = wdSectionNewPage
        .OddAndEvenPagesHeaderFooter = False
        .DifferentFirstPageHeaderFooter = False
        .VerticalAlignment = wdAlignVerticalTop
        .SuppressEndnotes = False
        .MirrorMargins = False
        .TwoPagesOnOne = False
        .BookFoldPrinting = False
        .BookFoldRevPrinting = False
        .BookFoldPrintingSheets = 1
        .GutterPos = wdGutterPosLeft

    End With<o:p></o:p>
 
Upvote 0
Thank you, However the lines of code with 'wd' starting it doesnt work, the field remains "Empty".

???

:ROFLMAO:
 
Upvote 0
Hi, I was only addressing the compile error in my response, however I'm not sure how much more help I can be as I don't really know much about word and more importantly I don't know what you are trying to do.

the lines of code with 'wd' starting it doesnt work, the field remains "Empty".

I don't see any lines of code that start with 'wd' and I don't see any code that creates or populates a "field" - whatever that might be.
 
Upvote 0

Forum statistics

Threads
1,216,783
Messages
6,132,678
Members
449,747
Latest member
OldMrsMol

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