• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 348
  • Last Modified:

Programmatically Change 'Browse in same ...

I would like to know if and how I can programatically set the 'Browse in same window' option in control panel/folders/file types for .doc and .xls files using Visual Basic 6. The program would get the current setting, change the setting, then put it back like it was when the program ends. Thanks
0
TSFl180PM
Asked:
TSFl180PM
  • 2
1 Solution
 
Erick37Commented:
Here is a way to modify the setting for DOC files as described here:
http://support.microsoft.com/default.aspx?scid=kb;en-us;254918

The method for XLS files will be similar, different registry key.



Option Explicit

'saves the previous setting
Private m_savedBrowserFlags As Long

Private Sub Command1_Click()

    'Turn OFF Browse in Same Window for DOC files
    'and save the old value
    m_savedBrowserFlags = SetDOCBrowseInSameWindow()

End Sub

Private Sub Command2_Click()
   
    'RESTORE the old setting
    If m_savedBrowserFlags = 0 Then
   
        'only switch back if the original value was 0
        Call SetDOCBrowseInSameWindow(0)
   
    End If
   
End Sub

Private Function SetDOCBrowseInSameWindow(Optional NewValue As Long = 8) As Long
   
    'gets the value of the key
    'HKEY_CLASSES_ROOT\Word.Document.8\BrowserFlags (or system equivalent)
    Dim WshShell As Object
    Dim sCurVer As String
    Dim sKey As String
    Dim lFlags As Long
   
    On Error Resume Next
   
    Set WshShell = CreateObject("WScript.Shell")
   
    'get the current version of Word
    sCurVer = WshShell.regread("HKEY_CLASSES_ROOT\Word.Document\CurVer\")
    'the key to the DOC browser settings
    sKey = "HKEY_CLASSES_ROOT\" & sCurVer & "\BrowserFlags"
   
    If sCurVer <> "" Then
   
        'get the old value of the setting
        lFlags = WshShell.regread(sKey)
   
        'Write the new value (default 8) to BrowserFlags key to
        'turn off the "Browse in Same Window" option
       
        Call WshShell.regwrite(sKey, NewValue, "REG_DWORD")
       
        'return the old value
        SetDOCBrowseInSameWindow = lFlags
       
    End If
   
    Set WshShell = Nothing


End Function
0
 
TSFl180PMAuthor Commented:
Thanks Erick37. I works great. I have modified it and have it working for Excel and PowerPoint as well as Word documents. Thanks again.
0
 
Erick37Commented:
Glad it worked. Thanks for the A!
0

Featured Post

What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now