ZoomAll from a VBA Excel program

ZoomAll from a VBA Excel program

oransen
Collaborator Collaborator
1,818 Views
3 Replies
Message 1 of 4

ZoomAll from a VBA Excel program

oransen
Collaborator
Collaborator

I have inherited a piece of VBA which runs inside Excel and to which I have to add Zoom All. Here is the code, but the Zoom All part doesn't.

 

Sub AutocadSaveDWG()
    
On Error GoTo ASDWG_Err:
    
    Dim Application As AcadApplication
    Dim Document As AcadDocument
    Dim filepath As String, sDate As String, sTime As String
    Dim saveFolder, Filename As String
      
    Set Application = GetObject(, "AutoCAD.Application")
    Set Document = Application.ActiveDocument

    saveFolder = "C:\DisegniSviluppati\"
    
    sDate = GetFileNameString(Date)
    sTime = GetFileNameString(Time)
    
    ' This filename takes the type of machine and adds the date
    Filename = Worksheets("DEVES_TABLE").Range("D10") & "_" & sDate & "_(" & sTime & ")"
   
    filepath = saveFolder & Filename
    
    ' Application.ZoomExtents
    Application.ZoomAll
    
    Document.SaveAs filepath
        
    
    Exit Sub
    
ASDWG_Err:
    ShowErrorMsgBox ("AutocadSaveDWG")
    
End Sub

 

Neither ZoomAll nor ZoomExtents works. What have I missed?

 

0 Likes
Accepted solutions (1)
1,819 Views
3 Replies
Replies (3)
Message 2 of 4

grobnik
Collaborator
Collaborator

Hi @oransen could you try with

...
 Set Application = GetObject(, "AutoCAD.Application")
    Set Document = Application.ActiveDocument
.....
Application.Document.ZoomAll

 

Message 3 of 4

oransen
Collaborator
Collaborator
Accepted solution

Ok, sussed, I need to use Visible = true, like this:

 

 

    Application.Visible = True
    Application.ZoomExtents

 

Message 4 of 4

oransen
Collaborator
Collaborator

Thanks, I'll test that solution as well.

0 Likes