Error Checking in Excel
Thanks Thanks:  0
Likes Likes:  0
Results 1 to 3 of 3

Thread: AutoFit Selection

  1. #1
    Guest

    Default

    I have downloaded some data from a webpage into Excel. The data is put into excel and is still highlighted. However the user needs to do Format -> Column -> AutoFit Selection

    How can I get my javascript to automatically do this?

    SCRIPT LANGUAGE="JScript">

    function bringToExcel(src)
    {
    document.selection.clear;
    txt = eval(src +".innerText");
    theObj = document.all(txt);
    txtRange = document.body.createTextRange();
    txtRange.moveToElementText(eval(src));
    txtRange.select();
    // uncomment line below to use with formatted (innerHTML) text
    // txtRange.execCommand("RemoveFormat");
    txtRange.execCommand("Copy");
    txtRange.execCommand("UnSelect", false);

    false);
    var oXL = new ActiveXObject("Excel.Application");
    oXL.Visible = true;
    var oWB = oXL.Workbooks.Add();
    var oSheet = oWB.ActiveSheet;
    oSheet.Paste();
    oXL.Visible = true;
    oXL.UserControl = true;
    }

    **************************
    I need a line after the oSheet.Paste(); to tell it to autofit the selection. What is the syntax for this?

  2. #2
    MrExcel MVP
    Join Date
    Feb 2002
    Location
    Bogota, Colombia
    Posts
    11,959
    Post Thanks / Like
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Default

    Try with

    oSheet.Cells.EntireColumn.AutoFit
    Regards,

    Juan Pablo González
    http://www.juanpg.com

  3. #3
    Guest

    Default

    Many Juan thanks, it worked!

Some videos you may like

User Tag List

Like this thread? Share it with others

Like this thread? Share it with others

Posting Permissions

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