Home |
Search |
Today's Posts |
|
#1
![]()
Posted to microsoft.public.excel.programming
|
|||
|
|||
![]()
Salve a tutti,
sto modificando un file (modello) excel che mi hanno passato, per gestire degli inserimenti di dati. All'interno del primo foglio è già presente un tasto per salvare la scheda compilata in un file a parte. Sul tasto è attivo il seguente codice VBA: "Sub Salva() ' ' Salva Macro ' Dim Forli As String Dim Sav As String 'questa variabile assimila il dato che hai in una cella, per prendere il nome, 'con cui salvare il solo foglio, io ho messo la A1, tu metterai la tua cella, vedi sotto Forli = Range("F2").Value Sav = Range("H2").Value 'queste sotto sono le istruzioni in cui devi fornire il percorso, io ho messo C:\Temp, tu metti la tua cartella ActiveWorkbook.SaveAs Filename:="C:\Documents and Settings\<username\Documenti\Schede\" & Forli & "_" & Sav & ".xls", FileFormat:= _ xlNormal, Password:="", WriteResPassword:="", ReadOnlyRecommended:=False _ , CreateBackup:=False ActiveWindow.Close ' End Sub" Alla voce ActiveWorkbook.SaveAs Filename:="......" io vorrei sostituire l'attuale percorso e mettere la path di windows generale (tipo %userprofile%) in modo che se sposto il file su un altro computer non mi dia errore nel salvataggio perchè il nome utente è diverso. Nel tentare questa cosa ho provato ad inserire %userprofile%\Documenti\Schede ma mi da errore e nel messaggio mi mostra il percorso ripetuto. Se metto solo %userprofile% invece mi salva il file nella cartella Documenti. Dove sbaglio ad inserire il path generale? P.s. il file viene usato rpincipalmente su 3 computer con Windows 2000, Xp Pro e Seven. Grazie per l'attenzione. -- M@rco. |
#2
![]()
Posted to microsoft.public.excel.programming
|
|||
|
|||
![]()
Marco ha pensato forte :
Salve a tutti, sto modificando un file (modello) excel che mi hanno passato, per gestire degli inserimenti di dati. All'interno del primo foglio è già presente un tasto per salvare la scheda compilata in un file a parte. Sul tasto è attivo il seguente codice VBA: "Sub Salva() ' ' Salva Macro ' Dim Forli As String Dim Sav As String 'questa variabile assimila il dato che hai in una cella, per prendere il nome, 'con cui salvare il solo foglio, io ho messo la A1, tu metterai la tua cella, vedi sotto Forli = Range("F2").Value Sav = Range("H2").Value 'queste sotto sono le istruzioni in cui devi fornire il percorso, io ho messo C:\Temp, tu metti la tua cartella ActiveWorkbook.SaveAs Filename:="C:\Documents and Settings\<username\Documenti\Schede\" & Forli & "_" & Sav & ".xls", FileFormat:= _ xlNormal, Password:="", WriteResPassword:="", ReadOnlyRecommended:=False _ , CreateBackup:=False ActiveWindow.Close ' End Sub" Alla voce ActiveWorkbook.SaveAs Filename:="......" io vorrei sostituire l'attuale percorso e mettere la path di windows generale (tipo %userprofile%) in modo che se sposto il file su un altro computer non mi dia errore nel salvataggio perchè il nome utente è diverso. Nel tentare questa cosa ho provato ad inserire %userprofile%\Documenti\Schede ma mi da errore e nel messaggio mi mostra il percorso ripetuto. Se metto solo %userprofile% invece mi salva il file nella cartella Documenti. Dove sbaglio ad inserire il path generale? P.s. il file viene usato rpincipalmente su 3 computer con Windows 2000, Xp Pro e Seven. Grazie per l'attenzione. Ho risolto, ho utilizzato questo codice: --- ActiveWorkbook.SaveAs _ Filename:=Environ("USERPROFILE") & "\Desktop\" & filename, _ FileFormat:=xlNormal --- -- M@rco. |
#3
![]()
Posted to microsoft.public.excel.programming
|
|||
|
|||
![]()
Marco wrote:
Marco ha pensato forte : Salve a tutti, sto modificando un file (modello) excel che mi hanno passato, per gestire degli inserimenti di dati. All'interno del primo foglio è già presente un tasto per salvare la scheda compilata in un file a parte. Sul tasto è attivo il seguente codice VBA: [snip code] Alla voce ActiveWorkbook.SaveAs Filename:="......" io vorrei sostituire l'attuale percorso e mettere la path di windows generale (tipo %userprofile%) in modo che se sposto il file su un altro computer non mi dia errore nel salvataggio perchè il nome utente è diverso. Nel tentare questa cosa ho provato ad inserire %userprofile%\Documenti\Schede ma mi da errore e nel messaggio mi mostra il percorso ripetuto. Se metto solo %userprofile% invece mi salva il file nella cartella Documenti. Dove sbaglio ad inserire il path generale? P.s. il file viene usato rpincipalmente su 3 computer con Windows 2000, Xp Pro e Seven. Grazie per l'attenzione. Ho risolto, ho utilizzato questo codice: --- ActiveWorkbook.SaveAs _ Filename:=Environ("USERPROFILE") & "\Desktop\" & filename, _ FileFormat:=xlNormal --- Various API calls are actually a more reliable choice. (Users can change the location of "My Documents", so you can't really trust %UserProfile%.) I use SHGetSpecialFolderPath (Microsoft claims it's only supported for Windows 2000, but it works for me under XP). Google traduzione: Diverse le chiamate API sono in realtà una scelta più affidabile. (Gli utenti possono modificare la posizione di "Documenti", così non si può davvero fidare %UserProfile%). Io uso SHGetSpecialFolderPath (Microsoft afferma che è supportato solo per Windows 2000, ma funziona per me sotto XP). Try this/Prova questo: Private Declare Function SHGetSpecialFolderPath Lib "shell32" _ Alias "SHGetSpecialFolderPathA" ( _ ByVal hwndOwner As Long, _ ByVal lpszPath As String, _ ByVal nFolder As Long, _ ByVal fCreate As Long) As Long Private Const MAX_PATH = 260 Private Const CSIDL_PERSONAL = 5 Sub Salva() Dim Forli As String Dim Sav As String Dim tmp1 As Long, tmp2 As Long Dim returnedPath As String Forli = Range("F2").Value Sav = Range("H2").Value returnedPath = Space$(MAX_PATH + 1) tmp1 = SHGetSpecialFolderPath(0, returnedPath, 5&, 0) tmp2 = InStr(returnedPath, Chr$(0)) 'Handle the terminating null, if present. 'Maneggiare il nullo di terminazione, se presente. If tmp2 Then returnedPath = Left$(returnedPath, tmp2 - 1) ActiveWorkbook.SaveAs Filename:=returnedPath & "\Schede\" & Forli & _ "_" & Sav & ".xls", _ FileFormat:=xlNormal ActiveWindow.Close End Sub (Note that the folder "Schede" must already exist, or this will fail./Si noti che il "Schede" cartella deve già esistere, o questo avrà esito negativo.) Alternately, you can just dig the path out of the registry. It's located at/In alternativa, si può solo scavare il percorso fuori dal Registro di sistema. Si trova a HKCU\Software\Microsoft\Windows\CurrentVersion\Exp lorer \Shell Folders\Personal. -- Seems every path leads me to nowhere. |
#4
![]()
Posted to microsoft.public.excel.programming
|
|||
|
|||
![]()
Auric__ ha usato la sua tastiera per scrivere :
Various API calls are actually a more reliable choice. (Users can change the location of "My Documents", so you can't really trust %UserProfile%.) I use SHGetSpecialFolderPath (Microsoft claims it's only supported for Windows 2000, but it works for me under XP). Google traduzione: Diverse le chiamate API sono in realtà una scelta più affidabile. (Gli utenti possono modificare la posizione di "Documenti", così non si può davvero fidare %UserProfile%). Io uso SHGetSpecialFolderPath (Microsoft afferma che è supportato solo per Windows 2000, ma funziona per me sotto XP). Try this/Prova questo: Private Declare Function SHGetSpecialFolderPath Lib "shell32" _ Alias "SHGetSpecialFolderPathA" ( _ ByVal hwndOwner As Long, _ ByVal lpszPath As String, _ ByVal nFolder As Long, _ ByVal fCreate As Long) As Long Private Const MAX_PATH = 260 Private Const CSIDL_PERSONAL = 5 Sub Salva() Dim Forli As String Dim Sav As String Dim tmp1 As Long, tmp2 As Long Dim returnedPath As String Forli = Range("F2").Value Sav = Range("H2").Value returnedPath = Space$(MAX_PATH + 1) tmp1 = SHGetSpecialFolderPath(0, returnedPath, 5&, 0) tmp2 = InStr(returnedPath, Chr$(0)) 'Handle the terminating null, if present. 'Maneggiare il nullo di terminazione, se presente. If tmp2 Then returnedPath = Left$(returnedPath, tmp2 - 1) ActiveWorkbook.SaveAs Filename:=returnedPath & "\Schede\" & Forli & _ "_" & Sav & ".xls", _ FileFormat:=xlNormal ActiveWindow.Close End Sub (Note that the folder "Schede" must already exist, or this will fail./Si noti che il "Schede" cartella deve già esistere, o questo avrà esito negativo.) Alternately, you can just dig the path out of the registry. It's located at/In alternativa, si può solo scavare il percorso fuori dal Registro di sistema. Si trova a HKCU\Software\Microsoft\Windows\CurrentVersion\Exp lorer \Shell Folders\Personal. Hi, thanks a lot for your solution. I will try it next days. In the pc where I use my solution are pc where the windows is configured normally and the personalize is blocked for normail user, so I can trust %userprofile% -- M@rco. |
Reply |
Thread Tools | Search this Thread |
Display Modes | |
|
|
![]() |
||||
Thread | Forum | |||
Windows cannot access the specified device, path or file. You may | Excel Discussion (Misc queries) | |||
ThisWorkbook.Path & Windows Vista | Excel Programming | |||
Windows API to Determine if File is Local/Convert Path to Drive Letter | Excel Programming | |||
hyperlink navigation path path wrong in Excel 2003 | Excel Discussion (Misc queries) | |||
Windows XP default path for temp file | Excel Programming |