
Private Sub UserForm_Initialize()
Application.ScreenUpdating = False
'Dichiaro le variabili
Dim xlApp As Excel.Application
Dim xlBook As Excel.Workbook
Dim xlSheet As Excel.Worksheet
Dim ValoreCella As String
Dim i As Integer
'Creo la nuova applicazione
Set xlApp = New Excel.Application
'apro il file di excel
Set xlbook = xlApp.Workbooks.Open("percorso
ome_file.xlsm")
'Decido quale foglio utilizzare
Set xlSheet = xlbook.Worksheets("Foglio1")
ur = xlSheet.Range("a" & Rows.Count).End(xlUp).Row
ciclo la colonna A
For i = 1 To ur
ValoreCella = xlSheet.Cells(i, 1).Value
inserimenti.ComboBox2.AddItem ValoreCella
inserimenti.ComboBox2.SpecialEffect = fmSpecialEffectFlat
Next i
'Chiudo il file di excel
xlBook.Close savechanges:=True
'chiudo excel
xlApp.Quit
'Annullo le variabili
'Set xlSheet = Nothing
'Set xlBook = Nothing
'Set xlApp = Nothing
Application.ScreenUpdating = True
End Sub |
Option Explicit
Private Sub UserForm_Initialize()
Application.ScreenUpdating = False
'Dichiaro le variabili
Dim xlApp As Excel.Application
Dim xlBook As Excel.Workbook
Dim xlSheet As Excel.Worksheet
Dim ValoreCella As String
Dim i As Integer
Dim ur As Long
On Error GoTo gest_err
'Creo la nuova applicazione
Set xlApp = New Excel.Application
'apro il file di excel
Set xlBook = xlApp.Workbooks.Open("g:pippo.xls")
'Decido quale foglio utilizzare
Set xlSheet = xlBook.Worksheets("Foglio1")
ur = xlSheet.Range("a" & xlSheet.Rows.Count).End(xlUp).Row
For i = 1 To ur
inserimenti.ComboBox2.AddItem xlSheet.Cells(i, 1).Value
Next i
'stranamente questo non riesco a farlo funzionare! sarebbe utile per eliminar eil for precedente :(
'inserimenti.ComboBox2.RowSource = "A1:A" & ur
inserimenti.ComboBox2.SpecialEffect = fmSpecialEffectFlat
gest_err:
If Err <> 0 Then
MsgBox "Errors occurred:" & vbCrLf & Err.Description
End If
'Chiudo il file di excel
xlBook.Close savechanges:=True
'chiudo excel
xlApp.Quit
'Annullo le variabili
Set xlSheet = Nothing
Set xlBook = Nothing
Set xlApp = Nothing
Application.ScreenUpdating = True
End Sub |
Option Explicit
Private Sub UserForm_Initialize()
Application.ScreenUpdating = False
'Dichiaro le variabili
Dim xlApp As Excel.Application
Dim xlBook As Excel.Workbook
Dim xlSheet As Excel.Worksheet
Dim ValoreCella As String
Dim i As Integer
Dim ur As Long
On Error GoTo gest_err
'Creo la nuova applicazione
Set xlApp = New Excel.Application
'apro il file di excel
Set xlBook = xlApp.Workbooks.Open("g:pippo.xls")
'Decido quale foglio utilizzare
Set xlSheet = xlBook.Worksheets("Foglio1")
ur = xlSheet.Range("a" & xlSheet.Rows.Count).End(xlUp).Row
inserimenti.ComboBox2.List = xlSheet.Range("A1:A" & ur).Value '<<<<<<<<
inserimenti.ComboBox2.SpecialEffect = fmSpecialEffectFlat
gest_err:
If Err <> 0 Then
MsgBox "Errors occurred:" & vbCrLf & Err.Description
End If
'Chiudo il file di excel
xlBook.Close savechanges:=True
'chiudo excel
xlApp.Quit
'Annullo le variabili
Set xlSheet = Nothing
Set xlBook = Nothing
Set xlApp = Nothing
Application.ScreenUpdating = True
End Sub
|
Private Sub ComboBox1_Change()
ThisDocument.TextBox1.Text = UserForm1.ComboBox1
End Sub
Private Sub UserForm_Initialize()
Dim r As Variant
For r = 1 To ActiveDocument.Tables(1).Rows.Count
Set myrange = ActiveDocument.Tables(1).Cell(r, 1).Range
myrange.MoveEnd Unit:=wdCharacter, Count:=-1
UserForm1.ComboBox1.AddItem myrange.Text
Next r
End Sub |
Private Sub ComboBox1_Change()
ThisDocument.TextBox1.Text = UserForm1.ComboBox1
End Sub
Private Sub UserForm_Initialize()
Dim r As Long, s as string
For r = 1 To ActiveDocument.Tables(1).Rows.Count
s = ActiveDocument.Tables(1).Cell(r, 1).Range.Text
UserForm1.ComboBox1.AddItem Replace(s, vbCrLf, "")
Next r
End Sub |
Private Sub UserForm_Initialize()
Dim oTable As Table
Dim i As Long, j As Long, m As Long, n As Long
Dim myArray() As Variant
Dim oData As Range
Dim oCell As Range
Dim oRow As Row
Application.ScreenUpdating = False
Set oTable = ThisDocument.Tables(1)
i = oTable.Rows.Count
j = oTable.Columns.Count
ReDim myArray(i - 1, j - 1)
For n = 0 To j - 1
For m = 1 To i - 1
Set oData = oTable.Cell(m + 1, n + 1).Range
oData.End = oData.End - 1
If oData.Text <> "" Then
myArray(m, n) = oData.Text
Else
myArray(m, n) = " "
End If
Next m
Next n
With UserForm1
With .ComboBox1
.List = myArray
End With
End With
Application.ScreenUpdating = True
End Sub |
v = activedocument.Tables(1).Range
x = replace(replace(v, chr(13)+chr(7), ";"), ";;", "-")
x = left(x, len(x)-1)
UserForm1.ComboBox1.List = x
Private Sub UserForm_Initialize()
Dim myCells As String, ocells As Range
ur = ActiveDocument.Tables(1).Rows.Count
With ThisDocument
Set ocells = .Range(Start:=.Tables(1).Cell(1, 1).Range.Start, _
End:=.Tables(1).Cell(ur, 1).Range.End)
myCells = ocells.Text
x = Array(myCells)
UserForm1.ComboBox1.List = x
End With
End Sub
|
Private Sub UserForm_Initialize()
Dim ocells As Variant, itm As Variant
With ActiveDocument
Set ocells = .Tables(1).Range
For Each itm In Split(ocells, Chr(13) + Chr(7))
If itm <> "" Then ComboBox1.AddItem itm
Next
End With
End Sub |
Private Sub UserForm_Initialize()
Dim ocells As Variant, x As Variant
With ActiveDocument
Set ocells = .Tables(1).Range
x = Replace(Replace(ocells, Chr(13) + Chr(7), ";"), ";;", "-")
x = Left(x, Len(x) - 1)
ComboBox1.List = Split(x, "-")
End With
End Sub |
Dim sngStartTime As Single Dim sngTotalTime As Single sngStartTime = Timer 'istruzioni sngTotalTime = Timer - sngStartTime MsgBox "Tempo impiegato: " & Round(sngTotalTime, 4) & " secondi" |
