Condividi tramite

RIFERIMENTI VBIDE excel VBA

Anonimo
2013-12-27T09:15:48+00:00

Buongiorno 

Vorrei sapere se e possibile impostare i riferimenti VBIDE da codice VBA ... mi spiego meglio

Devo creare un nuovo workbook da uno esistente e impostare i riferimenti ad un add-in da me creato

gia impostato nel workbook sorgente  segue un esempio .. che ovviamente non funziona ...

potete darmi suggerimenti per favore

Public Function Add_IALReference(ByVal wb As Workbook)

Dim vbaEditor As VBIDE.VBE

Dim vbProject As VBIDE.vbProject

Dim chkRef As Reference

Dim Msg As String

Dim gsPath As String                  'Path to place addin in (if empty, librarypath will be used)

Dim gsAppName As String          'Name of Application

Dim gsFilename As String            'Name of Addin file

'Set Library Elements

gsFilename = wb.Names("theAddInName").RefersToRange.Value ( contenuto di una cella )

gsPath = wb.Names("theAddInPath").RefersToRange.Value          ( contenuto di una cella )

On Error Resume Next

' add ILibrary reference add-in in project

wb.vbProject.References.AddFromFile gsPath & gsFilename

If Err <> 0 And Err <> 32813 Then

MsgBox "Impossibile caricare Libreria ." & vbCrLf & Err.Description

End If

Add_IALEReference_End:

On Error GoTo 0

Exit Function

End Function

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

Risposta accettata dall'autore della domanda

Anonimo
2013-12-31T13:16:37+00:00

grazie per la riasposta ... ma piu o meno è la soluzione che ho gia provato ma non funziona.... 

mi spego meglio ... io dovrei creare un nuovo workbook da uno gia aperto ....

copiandovi dentro alcuni worksheet .. vedi sotto

Set newBook = Workbooks.Add

' Copy the Invoice Template

curBook.Sheets(theTemplate).Copy Before:=newBook.Sheets(1)

Set newSheet = newBook.Sheets(theTemplate)

' Rename the worksheet

newSheet.Name = "Fattura"

' Copy the Settings worksheet

Settings.Copy After:=newSheet

' Copy the price List worksheet

PriceList.Copy After:=newSheet

...

Ciao,

tra le tante opzioni di sicurezza che excel prevede, vi è anche quella che impedisce l'accesso diretto al codice VBA. Per ottenere quello che chiedi è prima di tutto necessario verificare che vi sia la spunta alla seguente opzione:

'Considera attendibile l'accesso al modello a oggetti dei progetti VBA' reperibile nelle Impostazioni Centro Protezione. (excel 2007)

Una volta abilitato, prova con la macro allegata.

Andrea.


Sub testAddReference()

Dim wb As Workbook

Set wb = Workbooks.Add

Call addReference(wb, "c:\MioPath\MioAddIn.xla")

End Sub

Sub addReference(wb As Workbook, sReference As String)

' IMPORTANT: needs 'Trust Access To Visual Basic Project' option checked

Dim vbp As Object, ref As Object

On Error GoTo Uffa

Set vbp = wb.VBProject

On Error Resume Next

Set ref = vbp.References.AddFromFile(sReference)

On Error GoTo 0

If ref Is Nothing Then MsgBox "Reference add failed: " & sReference, vbCritical

theEnd:

Set vbp = Nothing:  Set ref = Nothing

Exit Sub

Uffa:

'Debug.Print Err, Error(Err)

MsgBox "Reference add failed: " & vbNewLine & _

"'Trust Access To Visual Basic Project' option isn't checked!", vbCritical

Resume theEnd

End Sub


La risposta è stata utile?

0 commenti Nessun commento

2 risposte aggiuntive

Ordina per: Più utili
  1. Anonimo
    2013-12-28T09:32:54+00:00

    grazie per la riasposta ... ma piu o meno è la soluzione che ho gia provato ma non funziona.... 

    mi spego meglio ... io dovrei creare un nuovo workbook da uno gia aperto ....

    copiandovi dentro alcuni worksheet .. vedi sotto

    Set newBook = Workbooks.Add

    ' Copy the Invoice Template

    curBook.Sheets(theTemplate).Copy Before:=newBook.Sheets(1)

    Set newSheet = newBook.Sheets(theTemplate)

    ' Rename the worksheet

    newSheet.Name = "Fattura"

    ' Copy the Settings worksheet

    Settings.Copy After:=newSheet

    ' Copy the price List worksheet

    PriceList.Copy After:=newSheet

    ..purtroppo il workbook creato non "eredita"  tutti i riferimenti VBA  ( o almeno non riesco a farli ereditare )

    oltre a quelli classici ..

    • visual basic for application               ( ereditato )
    • Microsoft excel 14 object library      ( ereditato )
    • OLE Automation                             ( ereditato )
    • Microsoft Office 14 object library    ( ereditato )
    • Microsoft From 2.0 object library    (ereditato )
    • Microsoft Visual Basic for Application Extensibility ( ereditato )

    ne avrei anche uno relativo ad un componente aggiuntivo mio MiaLibreria.xla

    che purtroppo non viene ereditato

    ..la domanda è:

    esiste un metodo per fare ereditare al workbook creato con il suddetto metodo i riferimenti di

    componenti aggiuntivi creati da excel ( file.xla ) ?????

    .. avevo provato a farlo da codice aggiungendolo con il metodo di cui sopra .. ma mi da errore caricamento dll

    spero di essere stato sufficientemente chiaro ed esaustivo

    La risposta è stata utile?

    0 commenti Nessun commento
  2. Anonimo
    2013-12-27T09:55:57+00:00

    Buongiorno 

    Vorrei sapere se e possibile impostare i riferimenti VBIDE da codice VBA ... mi spiego meglio

    <cut>

    Se(se) ho capito, vedi (in inglese):

    La risposta è stata utile?

    0 commenti Nessun commento