Aprire da access un excel su un determianto foglio

di Anonimizzato9151 il
5 risposte
Buona Sera,
verrei se possibile un aiutino in merito ad una apertura di un foglio excel in un determinato percorso dove sono presenti tanti file excel di con diversi fogli all’interno.
Ho creato una Form1 di ricerca che apre una Form2 dove all’interno ho:
Prodotto
Scaffale
Mese
Scaffale corrisponde al NOME del FILE EXCEL
Mese corrisponde al NOME dei FOGLI EXCEL ( foglio1= Gennaio , foglio2 = Febbraio ect)
 "Private Sub Comando15_Click()
Dim strInput As String
    strInput = ("D:\Utente\Michele\Desktop\Magazzino\" & Me!Scaffale & ".xlsx")
    Application.FollowHyperlink strInput, , True
    GetUserAddress = True
  End Sub
";
C’è un modo per aprire il foglio che è scritto nella Textbox “Mese”?

5 Risposte

  • Per fare quello che chiedi, FollowHyperlink non ci arriva più di tanto. Occorre far "dialogare" adeguatamente Access con Excel, i suoi FOGLI e si può anche arrivare alle singole CELLE. Questo codice è più articolato di ciò che chiedi. Prova a vedere tu cosa puoi eliminare/semplificare.
    Private Sub VediMappaScaffale_Click()
    Dim xlApp As Object
    Dim wb As Object
    Dim ws As Object
    Dim trova As Object
    Dim strPath As String, strLuogo As String
    Dim strFoglio As String, strCella As String, strAppActivate As String
    strLuogo = Me!Luogo
    strPath = CurrentProject.Path & "\Mappe\" & strLuogo & ".xlsx"
    If Dir(strPath) <> "" Then
        strFoglio = Me!Mobile
        strCella = Me!Scaffale
        Set xlApp = CreateObject("Excel.Application")
        xlApp.Visible = True
        Set wb = xlApp.Workbooks.Open(strPath)
        wb.Activate
        strAppActivate = strLuogo & ".xlsx - Excel"
        AppActivate (strAppActivate) 'si scrive il Titolo della finestra
        Set ws = wb.Worksheets(strFoglio)
        ws.Activate
        ws.Select
        Set trova = ws.Cells.Find(strCella)
        trova.Activate
        trova.Select
        Set trova = Nothing
        Set ws = Nothing
        Set wb = Nothing
        Set xlApp = Nothing
        Else
        MsgBox "Non è possibile vedere la Mappa Scaffali"
    End If
    End Sub
  • Grazie Osvaldo... ma la routine si blocca
    If Dir(strPath) <> "" Then
  • In che senso? Che messaggio di errore ti dà?
    Considera che devi tutto adattare ai tuoi nomi di campi/controlli, il path deve essere coerente.
    Attenzione, vedo che quando assegni in strInput (nel tuo codice) ci metti delle parentesi che sono errate. Toglile.
  • StrPath = ("D:\Utente\Michele\Desktop\Magazzino\" & Me!Scaffale & ".xlsx")
    If Dir(strPath) <> "" Then

    Risolto ora funziona. Grazie tante
  • Le parentesi non servono a nulla

    StrPath = "D:\Utente\Michele\Desktop\Magazzino\" & Me!Scaffale & ".xlsx"
Devi accedere o registrarti per scrivere nel forum
5 risposte