+ Reply to Thread
Results 1 to 2 of 2
  1. #1
    Full Member
    Discipline
    Electrical
    btraemoore's Discipline Details
    Occupation
    Electrical Designer
    Discipline
    Electrical
    Using
    Electrical 2012
    Join Date
    Apr 2012
    Location
    Houston
    Posts
    55

    Default having save-as problems from autocad to excel...

    Registered forum members do not see this ad.

    Im trying to saveas the work ive done as a different file name, and i keep getting "script out of range" can some one throw me a bone?

    Code:
    ' Declare Working Directory
        Global Const WrkDir = "C:\Documents and Settings\moorerb\Desktop\asset worksheets\"
    ' Declare Excel Workbook name
        Global Const Master_WorkBook = WrkDir & "bptags.xls"
        Global Const Secondary_WorkBook = WrkDir & "mytemp.xls"
    ' Declare Excel Worksheet name
        Global Const Master_WorkSheet = "ccu3"
        Global Const Secondary_WorkSheet = "mytemp"
        
    
    Global workbooks As Object
    Global ExcelVer As Integer
    Global ExcelServer As Object
    Global ObjWorksheet As Object
    'Global SecWorksheet As Object
    'Global ObjWorkbook As Object
    Global FileSaveName As String
    ' end of global variables
    
    
    Sub RetrieveEXC()
        Set ExcelServer = CreateObject("Excel.Application.11")
            Set workbooks = ExcelServer.workbooks
            workbooks.Add ("C:\Documents and Settings\moorerb\Desktop\asset worksheets\mytemp.xls")
            workbooks.Open (Master_WorkBook)
            
        Set ObjWorksheet = ExcelServer.ActiveWorkbook.worksheets(Master_WorkSheet)
            'ExcelServer.WindowState = -4140
            ExcelServer.Visible = True
            
            FileSaveName = WrkDir & Dwg_Name & ".xls"
            'Set SecWorksheet = ExcelServer.ActiveWorkbook.worksheets(Secondary_WorkSheet)
    
                        the line below is where my issue lyes.
            workbooks(Master_WorkBook).Sheets(Secondary_WorkSheet).Move After:=workbooks(Secondary_WorkBook).Sheets(1)
            workbooks(Secondary_WorkBook).SaveAs FileSaveName, fileformat:=56
            
            set_to_null
    '----------------------------------------------
            ActiveWorkbook.SaveAs FileName:= _
            FileSaveName, fileformat:= _
            xlNormal, Password:="", WriteResPassword:="", ReadOnlyRecommended:=False _
            , CreateBackup:=False
    '----------------------------------------------        
    End Sub
    these are my watches

    Watch : : Master_WorkBook : "C:\Documents and Settings\moorerb\Desktop\asset worksheets\bptags.xls" : String : Exwork
    Watch : : Master_WorkSheet : "ccu3" : String : Exwork
    Watch : : Secondary_WorkBook : "C:\Documents and Settings\moorerb\Desktop\asset worksheets\mytemp.xls" : String : Exwork
    Watch : : Secondary_WorkSheet : "template" : String : Exwork
    Watch : : FileSaveName : "C:\Documents and Settings\moorerb\Desktop\asset worksheets\B-4800-E-4419T.xls" : String : Exwork.RetrieveEXC
    Last edited by btraemoore; 24th May 2012 at 04:11 pm.

  2. #2
    Full Member
    Discipline
    Electrical
    btraemoore's Discipline Details
    Occupation
    Electrical Designer
    Discipline
    Electrical
    Using
    Electrical 2012
    Join Date
    Apr 2012
    Location
    Houston
    Posts
    55

    Default

    Registered forum members do not see this ad.

    just to update, this is the working code

    Code:
    '
    ' work done in excel
    '
    
    Sub excelwork()
        Dim i As Integer, n As Long, c As Long
            c = 8
        Dim CurrentItem As String
        Dim pause As Boolean
        Dim match As Variant
        Dim NewSheetName As String
            NewSheetName = Dwg_Name & "assets"
            
        'set a count for items in collection
        For i = 1 To EOC
        Cur_TxtSTR = text_coll(i)
        MasWorksheet.Activate
        MasWorksheet.cells(1, 3).Activate
        
            'set a count for items in excel spreadsheet
            For n = 1 To 876
            CurrentItem = MasWorksheet.cells(n, 3).Value
                
                'compare collection item to each excel item, until we find our match
                If Cur_TxtSTR = CurrentItem Then
                    MasWorksheet.Rows(n).Select                ' select the row
                    MasWorksheet.Rows(n).Copy                  ' copy the row
                    secWorksheet.Activate
                    secWorksheet.cells(c, 1).Activate
                    secWorksheet.paste                         ' paste the row in the new sheet
                    secWorksheet.cells(c, 10).Value = Dwg_Name ' insert the drawing name in new sheet
                    c = c + 1
                End If
        
            Next n
            
        Next i
        
        secWorksheet.Copy ' copy the new sheet
        ExcelServer.activeworkbook.sheets("template").Name = NewSheetName ' set the new sheet name
        FileSaveName = ExcelServer.Application.GetSaveAsFilename _
        (InitialFileName:=Dwg_Name & ".xls", Title:="Save As")            ' choose where we're going to save it
        
        If FileSaveName = "False" Then                         ' error handleing
            MsgBox "File not Saved, Actions Cancelled."
            Exit Sub
        Else
            ExcelServer.activeworkbook.SaveAs FileSaveName ' save it
            ExcelServer.activeworkbook.Close               ' close it
        End If
        
        ExcelServer.Application.DisplayAlerts = False ' hide unwanted alerts
        ExcelServer.workbooks("bptags.xls").Close     ' close the work book
        ExcelServer.Quit                              ' quit excel
        set_to_nil                                    ' function to reset object variables to nothing
        
    End Sub
    This is my blog, fell free to drop by and look or correct
    http://showyourcode.blogspot.com/
    Last edited by btraemoore; 21st Jun 2012 at 02:52 pm.

Similar Threads

  1. Save command problems
    By STAN G in forum AutoCAD Beginners' Area
    Replies: 5
    Last Post: 2nd Mar 2012, 09:20 am
  2. Autocad doesn´t prompt to save, just save
    By gilsoto13 in forum AutoCAD Bugs, Error Messages & Quirks
    Replies: 1
    Last Post: 7th Apr 2010, 08:08 pm
  3. Load and Save problems
    By christreeroot in forum AutoCAD General
    Replies: 2
    Last Post: 1st Jun 2009, 03:30 pm
  4. AutoCAD PnID excel import problems
    By tomb020871 in forum P&ID
    Replies: 2
    Last Post: 30th Jun 2008, 09:59 pm
  5. Problems with render and save
    By Pocket in forum AutoCAD 3D Modelling & Rendering
    Replies: 1
    Last Post: 25th May 2007, 02:43 am

Bookmarks

Posting Permissions

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