Este fórum está sendo desativado

Depois de 9 anos, este fórum será desativado. Mas calma.... estamos migrando para uma comunidade no DISCORD. Junte-se a nós.

ENTRAR PARA DISCORD

Tópicos relacionados a códigos VBA, gravação de macros, etc.
#45319
ola... boa noite.

preciso de uma macro pra abrir uma outra pasta de trabalho... assim,

estou com a pasta de trabalho "A" aberta e quero abrir a pasta de trabalho "B". mas se esta outra pasta de trabalho "B" já estiver aberta, somente vai selecionar a plan1 da pasta "B".
consegui fazer abrir a pasta "B" com Workbooks.Open "C:\...Cópia.xlsm"
mas retornar pra "B" depois de aberta nao consegui.

no aguardo.
obrigado.
#45324
Veja se ajuda
Código: Selecionar todos
Option Explicit
Public Sub AbrirPastaTrabalho()
    Const strNomeArq As String = "Cronograma_Cursos.xlsx"
    Const strCaminho As String = "D:\Cursos"
    Dim wbk As Workbook
    
    If PastaAberta(strNomeArq:=strNomeArq) Then
        Workbooks(strNomeArq).Worksheets(1).Range("A1").Activate
    Else
        Set wbk = Workbooks.Open(Filename:=strCaminho & "\" & strNomeArq)
        wbk.Worksheets(1).Range("A1").Activate
    End If
End Sub


Private Function PastaAberta(strNomeArq As String) As Boolean
    Dim wbk     As Workbook
    Dim lngCont As Long
    
    For Each wbk In Application.Workbooks
        If wbk.Name = strNomeArq Then
            PastaAberta = True
            lngCont = lngCont + 1
        End If
    Next wbk
    
    If lngCont = 0 Then PastaAberta = False
End Function
long long title how many chars? lets see 123 ok more? yes 60

We have created lots of YouTube videos just so you can achieve [...]

Another post test yes yes yes or no, maybe ni? :-/

The best flat phpBB theme around. Period. Fine craftmanship and [...]

Do you need a super MOD? Well here it is. chew on this

All you need is right here. Content tag, SEO, listing, Pizza and spaghetti [...]

Lasagna on me this time ok? I got plenty of cash

this should be fantastic. but what about links,images, bbcodes etc etc? [...]

Estamos migrando para uma comunidade no Discord