Excel Immagini in Userform

Anonimo
2016-10-16T20:30:55+00:00

Chiedo cortesemente di correggere il listato sottostante. L'immagine riesco a selezionarla e poi inserirla nella userform, peccato che la fase di selezione delle immagini ha tempi molto lunghi.

Private Sub CommandButton2_Click()

Dim Selez As Variant

On Error GoTo errHandler

50 Sheets("Foglio1").Visible = xlSheetVisible

52 Sheets("Foglio1").Select

54    With Application.FileDialog(msoFileDialogOpen)

56        .AllowMultiSelect = False

58        .Filters.clear

60        .Filters.Add "Immagini", "*.JPG, *.JPEG,*.BMP, *.GIF"

62        .Show

64        For Each Selez In .SelectedItems

66            cells(10, 9) = Selez

68        Next

70    End With

72    If cells(10, 9) = ""  Then

74       Sheets("Foglio1").Visible = xlVeryHidden

76       Exit Sub

78    Else: End If

80    Image1_Click

82    Exit Sub

errHandler:

cells(1, 10) = err.Number & " " & err.Description & " (Frm20-" & Erl & ")"

Call Macro49

End Sub

Ringrazio e cortesemente Vi saluto

Microsoft 365 e Office | Excel | Per la casa | Windows

Domanda bloccata. Questa domanda è stata eseguita dalla community del supporto tecnico Microsoft. È possibile votare se è utile, ma non è possibile aggiungere commenti o risposte o seguire la domanda.

0 commenti Nessun commento

3 risposte

Ordina per: Più utili
  1. Anonimo
    2016-10-17T19:50:13+00:00

    Ciao Joseph,

    Grazie Norman,

    il tuo codice è perfetto. Mette in evidenza soprattutto le mie carenze nelle  definizioni  DIM e Oggetti.

    In futuro cercherò di migliorare.

    Mi fa piacere che tu abbia risolto il problema e ti ringrazio per il cortese riscontro.

    Per chiudere questo thread, vorrei chiederti gentilmente di segnare la mia risposta come Risposta. In questo modo, tu aiuterai anche coloro che potessero cercare soluzioni ai problemi simili negli archivi della Community.

    ===

    Regards,

    Norman

    La risposta è stata utile?

    0 commenti Nessun commento
  2. Anonimo
    2016-10-17T19:28:43+00:00

    Grazie Norman,

    il tuo codice è perfetto. Mette in evidenza soprattutto le mie carenze nelle  definizioni  DIM e Oggetti.

    In futuro cercherò di migliorare.

    La risposta è stata utile?

    0 commenti Nessun commento
  3. Anonimo
    2016-10-17T01:53:07+00:00

    Ciao Joseph,

    Chiedo cortesemente di correggere il listato sottostante. L'immagine riesco a selezionarla e poi inserirla nella userform, peccato che la fase di selezione delle immagini ha tempi molto lunghi.

    Private Sub CommandButton2_Click()

    Dim Selez As Variant

    On Error GoTo errHandler

    50 Sheets("Foglio1").Visible = xlSheetVisible

    52 Sheets("Foglio1").Select

    54    With Application.FileDialog(msoFileDialogOpen)

    56        .AllowMultiSelect = False

    58        .Filters.clear

    60        .Filters.Add "Immagini", "*.JPG, *.JPEG,*.BMP, *.GIF"

    62        .Show

    64        For Each Selez In .SelectedItems

    66            cells(10, 9) = Selez

    68        Next

    70    End With

    72    If cells(10, 9) = ""  Then

    74       Sheets("Foglio1").Visible = xlVeryHidden

    76       Exit Sub

    78    Else: End If

    80    Image1_Click

    82    Exit Sub

    errHandler:

    cells(1, 10) = err.Number & " " & err.Description & " (Frm20-" & Erl & ")"

    Call Macro49

    End Sub

    Priva qualcosa del genere:

    Option Explicit

    'Public sImmagine As String

    Private Sub CommandButton2_Click()

              Dim WB As Workbook

              Dim SH As Worksheet

              Dim FD As FileDialog

              Dim sImmagine As String

              Const sFoglio As String = "Foglio1"

    10        On Error GoTo errHandler

    20        Set WB = ThisWorkbook

    30        Set SH = WB.Sheets(sFoglio)

    40        With SH

    50            Sheets("Foglio1").Visible = xlSheetVisible

    60            Sheets("Foglio1").Select

    70        End With

    80        Set FD = Application.FileDialog(msoFileDialogOpen)

    90        With FD

    100           .AllowMultiSelect = False

    110           .Title = "Seleziona Immagine"

    120           .Filters.Clear

    130           .Filters.Add "Immagini", "*.JPG, *.JPEG,*.BMP, *.GIF"

    140           .InitialView = msoFileDialogViewDetails

    150           If .Show = True Then

    160               sImmagine = .SelectedItems(1)

    170               With Me

    180                   .Img1.Picture = LoadPicture(sImmagine)

    190                   .Repaint

    200               End With

    210           Else

    220               MsgBox "No"

    230               If SH.Cells(10, 9) = "" Then

    240                   Sheets("Foglio1").Visible = xlVeryHidden

    250                   Exit Sub

    260               End If

    270           End If

    280       End With

    290       SH.Cells(10, 9).Value = sImmagine

    XIT:

    300   Set FD = Nothing

    310       Exit Sub

    errHandler:

    320       SH.Cells(1, 10) = Err.Number & " " _

                              & Err.Description _

                              & " (Frm20-" & Erl & ")"

                 Call Macro49

    End Sub

    '<<=========

    A me, la selezione delle immagini è praticamente istantanea.

    ===

    Regards,

    Norman

    La risposta è stata utile?

    0 commenti Nessun commento