Consulting

Results 1 to 12 of 12

Thread: Solved: General questions on excel objects...

  1. #1

    Solved: General questions on excel objects...

    Hi,

    I'm trying to figure out how to approach exporting a bunch of information out of a workbook. The intent is to be able to open the file at a later date, import the information previously exported and return the file to the state it was in.
    (Currently we save the whole excel file and change it's name.) One of my issues with doing this is that certain things are established via checkboxes and dropdowns. So far I haven't seen anything promising about setting the state of a checkbox or a dropdown using VBA.

    Thanks for any bits of wisdom,
    David

  2. #2
    VBAX Mentor
    Joined
    Feb 2009
    Posts
    493
    Location
    Out of curiosity why not save the whole excel file and change it's name as you currently do?

  3. #3
    2.2mb per shot.
    Also, the next step is to get certain parts of the data out as xml and import them to a pdf form, (This is a quoting tool)

    thanks

  4. #4
    Knowledge Base Approver VBAX Guru GTO's Avatar
    Joined
    Sep 2008
    Posts
    3,368
    Location
    I would suggest attaching a small (not a 2.2m) sample workbook to show us what steps we are wanting to accomplish.

  5. #5
    Ok, let me see what I can separate without breaking too much.

  6. #6

    Here it is....

    I'm afraid it will create more questions than answers.
    1, first time it asks for a user id enter best@20e, the second time, any 3 letters
    2, The orange button that unhides sheets... bis is the password
    3, To access the vba - r5t5pq

    Now everyone will see what a mess I have created.
    Attached Files Attached Files

  7. #7
    Administrator
    VP-Knowledge Base
    VBAX Grand Master mdmackillop's Avatar
    Joined
    May 2004
    Location
    Scotland
    Posts
    14,489
    Location
    Here's my approach. Create text files to hold data and control values. These can be opened and the data transferred back to the original values.

    [VBA]Option Explicit

    Sub Export()
    Dim i As Long, j As Long
    Dim cel As Range
    Dim DataCells()
    Dim Ctrls()
    Dim ctl
    Dim fs, a

    ReDim DataCells(1, 5000)
    ReDim Ctrls(1, 5000)

    Set fs = CreateObject("Scripting.FileSystemObject")

    For Each cel In ActiveSheet.UsedRange.SpecialCells(xlCellTypeConstants)
    DataCells(0, i) = cel.Address
    DataCells(1, i) = cel.Value
    i = i + 1
    Next
    ReDim Preserve DataCells(1, i - 1)

    Set a = fs.CreateTextFile("c:\aaa\testfile.txt", True)
    For j = 0 To i - 1
    a.WriteLine Ctrls(0, j) & "," & Ctrls(1, j)
    Next
    a.Close

    On Error Resume Next
    i = 0
    For Each ctl In ActiveSheet.Shapes
    Select Case Split(ctl.Name)(0)
    Case "Drop"
    Ctrls(0, i) = ctl.Name
    Ctrls(1, i) = ActiveSheet.DropDowns(ctl.Name).ListIndex
    Case "Check"
    Ctrls(0, i) = ctl.Name
    Ctrls(1, i) = ActiveSheet.CheckBoxes(ctl.Name).Value
    Case Else
    'continue control options
    Ctrls(0, i) = ctl.Name
    Ctrls(1, i) = ctl.Type

    End Select
    i = i + 1
    Next
    On Error GoTo 0

    ReDim Preserve Ctrls(1, i - 1)

    Set a = fs.CreateTextFile("c:\aaa\Ctrlfile.txt", True)
    For j = 0 To i - 1
    a.WriteLine Ctrls(0, j) & "," & Ctrls(1, j)
    Next
    a.Close

    End Sub

    [/VBA]
    MVP (Excel 2008-2010)

    Post a workbook with sample data and layout if you want a quicker solution.


    To help indent your macros try Smart Indent

    Please remember to mark threads 'Solved'

  8. #8
    You Rock!
    I'm looking forward to trying this.

    Thanks,
    David

  9. #9
    Administrator
    VP-Knowledge Base VBAX Grand Master mdmackillop's Avatar
    Joined
    May 2004
    Location
    Scotland
    Posts
    14,489
    Location
    Hi David,
    I've reordered and reposted my code above. There was an error in using the same variable twice to write the text files.
    MVP (Excel 2008-2010)

    Post a workbook with sample data and layout if you want a quicker solution.


    To help indent your macros try Smart Indent

    Please remember to mark threads 'Solved'

  10. #10

    Many Many Thanks!

    By the way, Is that a Rhodesian Ridgeback in your avatar Photo?

  11. #11
    Administrator
    VP-Knowledge Base VBAX Grand Master mdmackillop's Avatar
    Joined
    May 2004
    Location
    Scotland
    Posts
    14,489
    Location
    It is. Sadly no longer with us.
    MVP (Excel 2008-2010)

    Post a workbook with sample data and layout if you want a quicker solution.


    To help indent your macros try Smart Indent

    Please remember to mark threads 'Solved'

  12. #12
    Nor is mine.
    Recently adopted a pair of retired Greyhounds though!

Posting Permissions

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