Click here to Skip to main content
15,898,222 members
Home / Discussions / Visual Basic
   

Visual Basic

 
GeneralRe: Connections with My SQL Pin
Hermawan266-Oct-16 16:46
Hermawan266-Oct-16 16:46 
QuestionHow to get a file in subfolder in UWP? Pin
jeffery c5-Oct-16 0:30
jeffery c5-Oct-16 0:30 
QuestionFinding the path to the pictures Pin
JR21227-Sep-16 0:29
JR21227-Sep-16 0:29 
AnswerRe: Finding the path to the pictures Pin
Dave Kreskowiak27-Sep-16 3:56
mveDave Kreskowiak27-Sep-16 3:56 
GeneralRe: Finding the path to the pictures Pin
Eddy Vluggen27-Sep-16 4:27
professionalEddy Vluggen27-Sep-16 4:27 
GeneralRe: Finding the path to the pictures Pin
JR21227-Sep-16 4:46
JR21227-Sep-16 4:46 
GeneralRe: Finding the path to the pictures Pin
Eddy Vluggen27-Sep-16 6:27
professionalEddy Vluggen27-Sep-16 6:27 
AnswerRe: Finding the path to the pictures Pin
Richard Deeming27-Sep-16 5:38
mveRichard Deeming27-Sep-16 5:38 
For VBA, you'll need to use either SHGetFolderPath[^] or the newer SHGetKnownFolderPath[^].

How To Use the SHGetFolderPath Function from Visual Basic[^]
VB
Option Explicit

Private Const S_OK = &H0
Private Const S_FALSE = &H1
Private Const E_INVALIDARG = &H80070057

Private Const MAX_PATH = 260
Private Const SHGFP_TYPE_CURRENT = 0
Private Const CSIDL_MYPICTURES = &H27

Private Declare Function SHGetFolderPath Lib "shfolder" _
    Alias "SHGetFolderPathA" _
    (ByVal hwndOwner As Long, ByVal nFolder As Long, _
    ByVal hToken As Long, ByVal dwFlags As Long, _
    ByVal pszPath As String) As Long

Private Function GetFolderPath(ByVal csidl As Long) As String
    Dim path As String
    Dim returnValue As Long
    
    path = String(MAX_PATH, 0)
    returnValue = SHGetFolderPath(0, csidl, 0, SHGFP_TYPE_CURRENT, path)
    
    Select Case returnValue
        Case S_OK
            GetFolderPath = Left(path, InStr(1, path, Chr(0)) - 1)
        
        Case S_FALSE
            ' The CSIDL in nFolder is valid, but the folder does not exist.
            ' Use CSIDL_FLAG_CREATE to have it created automatically
            GetFolderPath = vbNullString
        
        Case E_INVALIDARG
            ' nFolder is invalid
            Err.Raise 5, "csidl", "Invalid folder"
    End Select
End Function

Public Function GetPicturesFolderPath() As String
    GetPicturesFolderPath = GetFolderPath(CSIDL_MYPICTURES)
End Function


For script running locally, you could read the folder path from the registry (HKCU\SOFTWARE\Microsoft\Windows\CurrentVersion\Explorer\Shell Folders). However, there is a warning in that key telling you not to do that! Smile | :)

Since you can't call Windows functions directly from script, you'd need to create a COM object to call the Windows API, and invoke that object from your script.

For script running in the browser, there is no way to access this information.



EDIT: There's also HKCU\SOFTWARE\Microsoft\Windows\CurrentVersion\Explorer\User Shell Folders, which doesn't have that warning. But the recommendation is still to use the Windows API.

In other words, the "Shell Folders" key exists solely to permit four programs written in 1994 to continue running on the RTM version of Windows 95.




"These people looked deep within my soul and assigned me a number based on the order in which I joined."
- Homer



modified 27-Sep-16 11:59am.

GeneralRe: Finding the path to the pictures Pin
Dave Kreskowiak27-Sep-16 5:50
mveDave Kreskowiak27-Sep-16 5:50 
GeneralRe: Finding the path to the pictures Pin
Richard Deeming27-Sep-16 6:02
mveRichard Deeming27-Sep-16 6:02 
GeneralRe: Finding the path to the pictures Pin
Eddy Vluggen27-Sep-16 6:25
professionalEddy Vluggen27-Sep-16 6:25 
GeneralRe: Finding the path to the pictures Pin
Richard Deeming27-Sep-16 6:27
mveRichard Deeming27-Sep-16 6:27 
GeneralRe: Finding the path to the pictures Pin
Eddy Vluggen27-Sep-16 6:40
professionalEddy Vluggen27-Sep-16 6:40 
GeneralRe: Finding the path to the pictures Pin
Dave Kreskowiak27-Sep-16 6:49
mveDave Kreskowiak27-Sep-16 6:49 
GeneralRe: Finding the path to the pictures Pin
Dave Kreskowiak27-Sep-16 6:48
mveDave Kreskowiak27-Sep-16 6:48 
GeneralRe: Finding the path to the pictures Pin
Eddy Vluggen27-Sep-16 6:51
professionalEddy Vluggen27-Sep-16 6:51 
GeneralRe: Finding the path to the pictures Pin
Dave Kreskowiak27-Sep-16 6:54
mveDave Kreskowiak27-Sep-16 6:54 
GeneralRe: Finding the path to the pictures Pin
JR21228-Sep-16 7:16
JR21228-Sep-16 7:16 
GeneralRe: Finding the path to the pictures Pin
JR21230-Sep-16 11:05
JR21230-Sep-16 11:05 
GeneralRe: Finding the path to the pictures Pin
Dave Kreskowiak2-Oct-16 7:05
mveDave Kreskowiak2-Oct-16 7:05 
GeneralRe: Finding the path to the pictures Pin
JR2122-Oct-16 22:55
JR2122-Oct-16 22:55 
Questionappend value in vb6.0 Pin
Member 1257898824-Sep-16 18:34
Member 1257898824-Sep-16 18:34 
AnswerRe: append value in vb6.0 Pin
Richard MacCutchan24-Sep-16 20:38
mveRichard MacCutchan24-Sep-16 20:38 
AnswerRe: append value in vb6.0 Pin
Dave Kreskowiak25-Sep-16 3:55
mveDave Kreskowiak25-Sep-16 3:55 
Questionhow to count char in string Pin
Member 1257898824-Sep-16 17:49
Member 1257898824-Sep-16 17:49 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.