Results 1 to 7 of 7

Thread: Easy one

  1. #1

    Thread Starter
    Junior Member
    Join Date
    Jun 2000
    Posts
    21

    Question

    Hi,

    I think it's a very stupid question but I'd like to know the code to create a new excel document

    using nearly the same code :
    Set Newdoc = Word.Documents.Add

    Thanks in advance.

  2. #2
    Guest
    A la MSDN:

    CreateObject Function


    Creates and returns a reference to anActiveX object.

    Syntax

    CreateObject(class,[servername])

    The CreateObject function syntax has these parts:

    Part Description
    class Required; Variant (String). The application name and class of the object to create.
    servername Optional; Variant (String). The name of the network server where the object will be created.


    The classargument uses the syntax appname.objecttype and has these parts:

    Part Description
    appname Required; Variant (String). The name of the application providing the object.
    objecttype Required; Variant (String). The type orclass of object to create.


    Remarks

    Every application that supports Automation provides at least one type of object. For example, a word processing application may provide an Application object, a Document object, and a Toolbar object.

    To create an ActiveX object, assign the object returned by CreateObject to anobject variable:

    ' Declare an object variable to hold the object
    ' reference. Dim as Object causes late binding.
    Dim ExcelSheet As Object
    Set ExcelSheet = CreateObject("Excel.Sheet")

    This code starts the application creating the object, in this case, a Microsoft Excel spreadsheet. Once an object is created, you reference it in code using the object variable you defined. In the following example, you accessproperties andmethods of the new object using the object variable, ExcelSheet, and other Microsoft Excel objects, including the Application object and the Cells collection.

    ' Make Excel visible through the Application object.
    ExcelSheet.Application.Visible = True
    ' Place some text in the first cell of the sheet.
    ExcelSheet.Cells(1, 1).Value = "This is column A, row 1"
    ' Save the sheet to C:\test.doc directory.
    ExcelSheet.SaveAs "C:\ TEST.DOC"
    ' Close Excel with the Quit method on the Application object.
    ExcelSheet.Application.Quit
    ' Release the object variable.
    Set ExcelSheet = Nothing

    Declaring an object variable with the As Object clause creates a variable that can contain a reference to any type of object. However, access to the object through that variable is late bound; that is, the binding occurs when your program is run. To create an object variable that results in early binding, that is, binding when the program is compiled, declare the object variable with a specific class ID. For example, you can declare and create the following Microsoft Excel references:

    Dim xlApp As Excel.Application
    Dim xlBook As Excel.Workbook
    Dim xlSheet As Excel.WorkSheet
    Set xlApp = CreateObject("Excel.Application")
    Set xlBook = xlApp.Workbooks.Add
    Set xlSheet = xlBook.Worksheets(1)

    The reference through an early-bound variable can give better performance, but can only contain a reference to theclass specified in thedeclaration.

    You can pass an object returned by the CreateObject function to a function expecting an object as an argument. For example, the following code creates and passes a reference to a Excel.Application object:

    Call MySub (CreateObject("Excel.Application"))

    You can create an object on a remote networked computer by passing the name of the computer to the servername argument of CreateObject. That name is the same as the Machine Name portion of a share name: for a share named "\\\\MyServer\\Public," servername is "MyServer."

    The following code returns the version number of an instance of Excel running on a remote computer named MyServer:

    Dim xlApp As Object
    Set xlApp = CreateObject("Excel.Application", "MyServer")
    Debug.Print xlApp.Version

    If the remote server doesn’t exist or is unavailable, a run-time error occurs.

    Note Use CreateObject when there is no current instance of the object. If an instance of the object is already running, a new instance is started, and an object of the specified type is created. To use the current instance, or to start the application and have it load a file, use the GetObject function.

    If an object has registered itself as a single-instance object, only one instance of the object is created, no matter how many times CreateObject is executed.

  3. #3
    Fanatic Member
    Join Date
    Jul 2000
    Location
    Manchester NH
    Posts
    833
    I couldn't edit a cell.

    "Object doesn't support this property or method"



    where do I find info about an objects properties
    Kurt Simons
    [I know I'm a hack but my clients don't!]

  4. #4

    Thread Starter
    Junior Member
    Join Date
    Jun 2000
    Posts
    21

    Cool

    matthewralston, thanks for your answer.

  5. #5
    Guest
    I think you can open up VBA in Excel (CTRL+F11) an use the object browser to figure out the methods for editing cells.

    Better still, record a macro of when you edit a cell and just rip the code that Excel generated for you.

  6. #6
    Fanatic Member
    Join Date
    Jul 2000
    Location
    Manchester NH
    Posts
    833
    thanks
    Kurt Simons
    [I know I'm a hack but my clients don't!]

  7. #7
    Guest

    Bit of fun for ya :)

    Speakin of Excel... are you lot usin Excel 2000?
    1. Run Excel 2000.
    2. Select "Save as Web Page" from the File menu.
    3. Select "Save: Selection: Sheet".
    4. Check the "Add interactivity" box and click Save.
    5. Exit Excel 2000.
    6. Load the saved HTML page in Microsoft Internet Explorer 4/5.
    7. Scroll down to row 2000, column WC.
    8. Select row 2000 (activating the entire line) and then press Tab until WC is selected again.
    9. Hold down Shift + Ctrl + Alt, and click the MS Office logo in the upper left corner.
    10. Use the arrow keys to steer, space to fire, O (the letter "ou") to drop oil, and H to turn on the headlights.
    11. Hit Esc to exit the game.
    Found it on an easter egg site. Kept me amused for a while. Enjoy.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width