Public Sub carica_dati_Rettangoli()
PercorsoCompletoFileSelezionato = ""
ApriFile2 (cartella)
Dim LunghezzaPercorsoCompletoFileSelezionato As Integer
LunghezzaPercorsoCompletoFileSelezionato = Len(PercorsoCompletoFileSelezionato)
If LunghezzaPercorsoCompletoFileSelezionato = 0 Then Exit Sub
Dim NumeroCarattere As Integer
Dim Carattere As String
For NumeroCarattere = 0 To LunghezzaPercorsoCompletoFileSelezionato - 1
Carattere = Mid(PercorsoCompletoFileSelezionato, LunghezzaPercorsoCompletoFileSelezionato - NumeroCarattere, 1)
If Carattere = "" Then
nomefile = Right(PercorsoCompletoFileSelezionato, NumeroCarattere)
Exit For
End If
Next NumeroCarattere
On Error Resume Next
Dim Excel2 As Object
Dim excelSheet2 As Object
' Start Excel
On Error Resume Next
Set Excel2 = GetObject(, "Excel.Application")
If Err <> 0 Then
Err.Clear
Set Excel2 = CreateObject("Excel.Application")
If Err <> 0 Then
MsgBox "Could not load Excel.", vbExclamation
End
End If
End If
On Error GoTo 0
Excel2.Visible = True
Excel2.Workbooks.Open (PercorsoCompletoFileSelezionato)
Excel2.Sheets(1).Select
Dim i As Integer
Dim stringa As String
i = 2
Do Until Excel2.Sheets(1).Cells(i, 1).Value = ""
ThisDrawing.Application.Documents.Add
stringa = Excel2.Sheets(1).Cells(i, 1).Value & "," & Excel2.Sheets(1).Cells(i, 2).Value
ThisDrawing.SendCommand ("_rectangle" & vbCr & "0,0" & vbCr & stringa & vbCr)
ThisDrawing.SendCommand ("_zoom" & vbCr & "E" & vbCr)
i = i + 1
Loop
End Sub
Type ApriNomeFile
lStructSize As Long
hwndOwner As Long
hInstance As Long
lpstrFilter As String
lpstrCustomFilter As String
nMaxCustFilter As Long
nFilterIndex As Long
lpstrFile As String
nMaxFile As Long
lpstrFileTitle As String
nMaxFileTitle As Long
lpstrInitialDir As String
lpstrTitle As String
flags As Long
nFileOffset As Integer
nFileExtension As Integer
lpstrDefExt As String
lCustData As Long
lpfnHook As Long
lpTemplateName As String
End Type
Public Declare Function GetOpenFileName Lib "comdlg32.dll" Alias "GetOpenFileNameA" (pOpenfilename As ApriNomeFile) As Long
Public PercorsoCompletoFileSelezionato As String
Public Sub ApriFile2(PercorsoPredefinito As String)
'Cartella fissa il percorso predefinito per la finestra di dialogo
PercorsoPredefinito = "c:"
Dim FinestraApri As ApriNomeFile
Dim VariabileDiControllo As Long
With FinestraApri
.lStructSize = Len(FinestraApri)
.lpstrFilter = "Dati Rettangoli" & vbNullChar & "*.*"
.nFilterIndex = 2
.lpstrDefExt = ""
.flags = cdlOFNFileMustExist Or cdlOFNPathMustExist
.lpstrTitle = "Seleziona percorso"
.nMaxFile = 356
.lpstrFile = Space$(255)
.lpstrInitialDir = PercorsoPredefinito
End With
VariabileDiControllo = GetOpenFileName(FinestraApri)
If VariabileDiControllo <> 0 Then
PercorsoCompletoFileSelezionato = Left(FinestraApri.lpstrFile, InStr(FinestraApri.lpstrFile, vbNullChar) - 1)
End If
End Sub |