[python-win32] AttributeError: 'NoneType' object has no attribute 'PageSetup'

Tim Johnson tojo2000 at gmail.com
Thu Jan 10 14:50:52 CET 2008


I can't test this right now, but just looking at the code it would appear
that wordapp.Documents.Add() is returning None instead of a word document
object.  Take out the close and quit lines and run it with python -i  or
type it in interactively and then you can do a dir() on the worddoc object
and double-check that it is really what's being created.

On Jan 10, 2008 3:23 AM, a_n_s_h_a_n <uvhs_t3p at yahoo.com> wrote:

> hi! newbie here. from the subject, there is an error in the code. could
> anyone please exlpain why? here's the code:
>
> import win32com.client
> filename = 'D:\\FR23\\tickets\\07120306-IEEEToCGenerator\\test.doc'
> wordapp = win32com.client.Dispatch("Word.Application")  # Create new Word
> Object
> wordapp.Visible = 0 # Word Application should`t be visible
> worddoc = wordapp.Documents.Add()   # Create new Document Object
> # Make some Setup to the Document:
> worddoc.PageSetup.Orientation = 0   # Portrait
> worddoc.PageSetup.LeftMargin = 72
> worddoc.PageSetup.TopMargin = 72
> worddoc.PageSetup.BottomMargin = 78.48
> worddoc.PageSetup.RightMargin = 72
> worddoc.Content.Font.Name <http://worddoc.content.font.name/> = 'Verdana'
> worddoc.Content.Font.Size = 10
> worddoc.Content.Paragraphs.TabStops.Add(100)
> worddoc.Content.InsertAfter('PDF Filename: ')
> worddoc.Content.MoveEnd
> worddoc.SaveAs(filename)
> worddoc.Close(SaveChanges = -1) # Close the Word Document
> wordapp.Quit()  # Close the Word Application
>
> Thanks
>
> ------------------------------
> Be a better friend, newshound, and know-it-all with Yahoo! Mobile. Try it
> now.<http://us.rd.yahoo.com/evt=51733/*http://mobile.yahoo.com/;_ylt=Ahu06i62sR8HDtDypao8Wcj9tAcJ+>
>
>
> _______________________________________________
> python-win32 mailing list
> python-win32 at python.org
> http://mail.python.org/mailman/listinfo/python-win32
>
>


-- 
_____________________
Ceci n'est pas un email.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://mail.python.org/pipermail/python-win32/attachments/20080110/ed9e8842/attachment.htm 


More information about the python-win32 mailing list