Results 1 to 3 of 3
  1. #1
    DazJWood is offline Novice
    Windows XP Access 2010 32bit
    Join Date
    Nov 2011
    Posts
    2

    Exporting To Excel And Formatting, Office 2010

    I have an Access 2003 database that now needs to run in Access 2010.

    Amongst the many changes I have so far had to make to forms and VBA I have now hit a wall trying to resolve a particular issue.

    I have a report that extracts to Excel and various bits of formatting are applied. This is all done via VBA.

    One part of the code draws a textbox and then populates it with text.

    The extract of code that is causing the problem is as follows:

    exlBook.Sheets("Extract").Shapes.AddTextbox(msoTex tOrientationHorizontal, 1520, 540, _
    384#, 180).Select

    For byta = 0 To objExcel.WorksheetFunction.Ceiling(Len(arrTextSumm ary(3)) / 200, 1)
    If byta = 0 Then
    objExcel.Selection.Characters((byta * 200) + 1).Insert String:=Left(arrTextSummary(3), 200)
    Else
    objExcel.Selection.Characters((byta * 200) + 1).Insert String:=Mid(arrTextSummary(3), (byta * 200) + 1, 200)
    End If
    Next byta

    The line in BOLD is the problem and reports the error -

    "Runtime error: 1004 Unable to get the Characters property of the TextBox class"

    This ran faultlessly in 2003 and though I have tried I cannot fathom how I need to rewrite this line in order to get the code to work.



    Can anyone help?

    Thanks in advance,

    Daz

  2. #2
    June7's Avatar
    June7 is offline VIP
    Windows XP Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    52,929
    Did the library Reference for Excel reset when you opened the project in 2010? For 2010 it changed from 12 to 14.

    I successfully tested creating textbox and setting value with simple procedure in Excel2010 VBA:
    Code:
    Sub AddTextBox()
        ActiveSheet.Shapes.AddTextBox(msoTextOrientationHorizontal, 2.5, 1.5, _
            116, 145).TextFrame.Characters.Text = "This is a test of inserting a text box to a sheet and adding some text."
        With Selection.Characters(Start:=1, Length:=216).Font
            .Name = "Arial"
            .FontStyle = "Regular"
            .Size = 10
            .Strikethrough = False
            .Superscript = False
            .Subscript = False
            .OutlineFont = False
            .Shadow = False
            .Underline = xlUnderlineStyleNone
            .ColorIndex = xlAutomatic
        End With
    End Sub
    So I know the Characters method works. Perhaps you need to start with simpler code that works then build it up.

    Could you put the code behind the Excel book?
    How to attach file: http://www.accessforums.net/showthread.php?t=70301 To provide db: copy, remove confidential data, run compact & repair, zip w/Windows Compression.

  3. #3
    DazJWood is offline Novice
    Windows XP Access 2010 32bit
    Join Date
    Nov 2011
    Posts
    2
    As an update:

    It seems that with Excel 2010 the characters property can now only access locations in strings that exist. The property has changed to zero based and by trying to access the 200th character it now becomes a value out of range.

    The way round it would be to access the 199 character, insert a space as well as the next 199 characters.

    However, it also seems that the 256 character limit has also been lifted now, so I can write all the characters in one hit.
    So I can just replace the whole For...Next loop with:

    objExcel.Selection.Characters.Text = arrTextSummary(3)

    It would be so much easier to error trap access if their error messages actually made more sense!!!

    June7, thanks for your reply.

    Daz

Please reply to this thread with any new information or opinions.

Similar Threads

  1. Mixing Access 2000 with Office 2010
    By fiveoaks in forum Access
    Replies: 3
    Last Post: 10-20-2011, 09:59 AM
  2. Replies: 17
    Last Post: 08-03-2011, 05:19 PM
  3. DateAdd error in MS Office 2010
    By Noah4x4 in forum Access
    Replies: 7
    Last Post: 03-15-2011, 05:08 PM
  4. Office 2010, 64 bit crashed
    By gppkuntz in forum Access
    Replies: 2
    Last Post: 12-21-2010, 06:28 PM
  5. Replies: 2
    Last Post: 01-24-2010, 09:19 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Other Forums: Microsoft Office Forums