Programmatically Change 'Browse in same ...

Posted on 2005-03-09
Medium Priority
Last Modified: 2012-06-27
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
Question by:TSFl180PM
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
LVL 32

Accepted Solution

Erick37 earned 2000 total points
ID: 13501219
Here is a way to modify the setting for DOC files as described here:

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

Author Comment

ID: 13508792
Thanks Erick37. I works great. I have modified it and have it working for Excel and PowerPoint as well as Word documents. Thanks again.
LVL 32

Expert Comment

ID: 13508847
Glad it worked. Thanks for the A!

Featured Post

Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Background What I'm presenting in this article is the result of 2 conditions in my work area: We have a SQL Server production environment but no development or test environment; andWe have an MS Access front end using tables in SQL Server but we a…
This article describes some techniques which will make your VBA or Visual Basic Classic code easier to understand and maintain, whether by you, your replacement, or another Experts-Exchange expert.
Get people started with the process of using Access VBA to control Excel using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Excel. Using automation, an Access application can laun…
Get people started with the utilization of class modules. Class modules can be a powerful tool in Microsoft Access. They allow you to create self-contained objects that encapsulate functionality. They can easily hide the complexity of a process from…
Suggested Courses

762 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question