Eu não tenho muito conhecimento no assunto,
a macro que foi elabora é a seguinte.
preciso somente que "pare" essa conexão para que eu possa abrir os outros arquivos sem ser no modo leitura.
Sub mudarconexao()
'
' mudarconexao Macro
'
'
Unload UserForm1
With ActiveWorkbook.Connections("Cadastro Clientes").OLEDBConnection
.BackgroundQuery = True
.CommandText = Array("'BANCO DE DADOS CLIENTE$'")
.CommandType = xlCmdTable
.Connection = Array( _
"OLEDB;Provider=Microsoft.ACE.OLEDB.12.0;User ID=Admin;Data Source=C:UsersgustavoDesktopNova pastaTERRAPLENAGEM GUIMARAES " _
, _
"SERRA LTDAExcelCadastro Clientes.xlsm;Mode=Share Deny Write;Extended Properties=""Jet OLEDB:Bypass UserInfo Validation=False;Je" _
, _
"t OLEDB:Bypass UserInfo Validation=False;Jet OLEDB:Bypass UserInfo Validation=False;Jet OLEDB:Bypass UserInfo Validation=False;H" _
, _
"DR=YES;"";Jet OLEDB:System database="""";Jet OLEDB:Registry Path="""";Jet OLEDB:Engine Type=37;Jet OLEDB:Database Locking Mode=0;Jet " _
, _
"OLEDB:Global Partial Bulk Ops=2;Jet OLEDB:Global Bulk Transactions=1;Jet OLEDB:New Database Password="""";Jet OLEDB:Create System " _
, _
"Database=False;Jet OLEDB:Encrypt Database=False;Jet OLEDB:Don't Copy Locale on Compact=False;Jet OLEDB:Compact Without Replica R" _
, "epair=False;Jet OLEDB:SFP=False;Jet OLEDB:Support Complex Data=False")
.RefreshOnFileOpen = False
.SavePassword = False
.SourceConnectionFile = ""
.SourceDataFile = _
"C:UsersgustavoDesktopTerraplenagem Guimarães Serra LTDAExcelCadastro Clientes.xlsm"
.ServerCredentialsMethod = xlCredentialsMethodIntegrated
.AlwaysUseConnectionFile = False
End With
With ActiveWorkbook.Connections("Cadastro Clientes")
.Name = "Cadastro Clientes"
.Description = ""
End With
ActiveWorkbook.Connections("Cadastro Clientes").Refresh
With ActiveWorkbook.Connections("Cadastro de Nota").OLEDBConnection
.BackgroundQuery = True
.CommandText = Array("NOTA$")
.CommandType = xlCmdTable
.Connection = Array( _
"OLEDB;Provider=Microsoft.ACE.OLEDB.12.0;User ID=Admin;Data Source=C:UsersgustavoDesktopNova pastaTERRAPLENAGEM GUIMARAES " _
, _
"SERRA LTDAExcelCadastro de Nota.xlsm;Mode=Share Deny Write;Extended Properties=""Jet OLEDB:Bypass UserInfo Validation=False;Jet" _
, _
" OLEDB:Bypass UserInfo Validation=False;Jet OLEDB:Bypass UserInfo Validation=False;Jet OLEDB:Bypass UserInfo Validation=False;HD" _
, _
"R=YES;"";Jet OLEDB:System database="""";Jet OLEDB:Registry Path="""";Jet OLEDB:Engine Type=37;Jet OLEDB:Database Locking Mode=0;Jet O" _
, _
"LEDB:Global Partial Bulk Ops=2;Jet OLEDB:Global Bulk Transactions=1;Jet OLEDB:New Database Password="""";Jet OLEDB:Create System D" _
, _
"atabase=False;Jet OLEDB:Encrypt Database=False;Jet OLEDB:Don't Copy Locale on Compact=False;Jet OLEDB:Compact Without Replica Re" _
, "pair=False;Jet OLEDB:SFP=False;Jet OLEDB:Support Complex Data=False")
.RefreshOnFileOpen = False
.SavePassword = False
.SourceConnectionFile = ""
.SourceDataFile = _
"C:UsersgustavoDesktopTerraplenagem Guimarães Serra LTDAExcelCadastro de Nota.xlsm"
.ServerCredentialsMethod = xlCredentialsMethodIntegrated
.AlwaysUseConnectionFile = False
End With
With ActiveWorkbook.Connections("Cadastro de Nota")
.Name = "Cadastro de Nota"
.Description = ""
End With
ActiveWorkbook.Connections("Cadastro de Nota").Refresh
With ActiveWorkbook.Connections("Cadastro Equipamento2").OLEDBConnection
.BackgroundQuery = True
.CommandText = Array("equipamentos$")
.CommandType = xlCmdTable
.Connection = Array( _
"OLEDB;Provider=Microsoft.ACE.OLEDB.12.0;User ID=Admin;Data Source=C:UsersgustavoDesktopNova pastaTERRAPLENAGEM GUIMARAES " _
, _
"SERRA LTDAExcelCadastro Equipamento2.xlsm;Mode=Share Deny Write;Extended Properties=""Jet OLEDB:Bypass UserInfo Validation=Fals" _
, _
"e;Jet OLEDB:Bypass UserInfo Validation=False;Jet OLEDB:Bypass UserInfo Validation=False;Jet OLEDB:Bypass UserInfo Validation=Fal" _
, _
"se;HDR=YES;"";Jet OLEDB:System database="""";Jet OLEDB:Registry Path="""";Jet OLEDB:Engine Type=37;Jet OLEDB:Database Locking Mode=0;" _
, _
"Jet OLEDB:Global Partial Bulk Ops=2;Jet OLEDB:Global Bulk Transactions=1;Jet OLEDB:New Database Password="""";Jet OLEDB:Create Sys" _
, _
"tem Database=False;Jet OLEDB:Encrypt Database=False;Jet OLEDB:Don't Copy Locale on Compact=False;Jet OLEDB:Compact Without Repli" _
, "ca Repair=False;Jet OLEDB:SFP=False;Jet OLEDB:Support Complex Data=False")
.RefreshOnFileOpen = False
.SavePassword = False
.SourceConnectionFile = ""
.SourceDataFile = _
"C:UsersgustavoDesktopTerraplenagem Guimarães Serra LTDAExcelCadastro Equipamento2.xlsm"
.ServerCredentialsMethod = xlCredentialsMethodIntegrated
.AlwaysUseConnectionFile = False
End With
With ActiveWorkbook.Connections("Cadastro Equipamento2")
.Name = "Cadastro Equipamento2"
.Description = ""
End With
ActiveWorkbook.Connections("Cadastro Equipamento2").Refresh
With ActiveWorkbook.Connections("Cadastro Transportes").OLEDBConnection
.BackgroundQuery = True
.CommandText = Array("Transportes$")
.CommandType = xlCmdTable
.Connection = Array( _
"OLEDB;Provider=Microsoft.ACE.OLEDB.12.0;User ID=Admin;Data Source=C:UsersgustavoDesktopNova pastaTERRAPLENAGEM GUIMARAES " _
, _
"SERRA LTDAExcelCadastro Transportes.xlsm;Mode=Share Deny Write;Extended Properties=""Jet OLEDB:Bypass UserInfo Validation=False" _
, _
";Jet OLEDB:Bypass UserInfo Validation=False;Jet OLEDB:Bypass UserInfo Validation=False;Jet OLEDB:Bypass UserInfo Validation=Fals" _
, _
"e;HDR=YES;"";Jet OLEDB:System database="""";Jet OLEDB:Registry Path="""";Jet OLEDB:Engine Type=37;Jet OLEDB:Database Locking Mode=0;J" _
, _
"et OLEDB:Global Partial Bulk Ops=2;Jet OLEDB:Global Bulk Transactions=1;Jet OLEDB:New Database Password="""";Jet OLEDB:Create Syst" _
, _
"em Database=False;Jet OLEDB:Encrypt Database=False;Jet OLEDB:Don't Copy Locale on Compact=False;Jet OLEDB:Compact Without Replic" _
, "a Repair=False;Jet OLEDB:SFP=False;Jet OLEDB:Support Complex Data=False")
.RefreshOnFileOpen = False
.SavePassword = False
.SourceConnectionFile = ""
.SourceDataFile = _
"C:UsersgustavoDesktopTerraplenagem Guimarães Serra LTDAExcelCadastro Transportes.xlsm"
.ServerCredentialsMethod = xlCredentialsMethodIntegrated
.AlwaysUseConnectionFile = False
End With
With ActiveWorkbook.Connections("Cadastro Transportes")
.Name = "Cadastro Transportes"
.Description = ""
End With
ActiveWorkbook.Connections("Cadastro Transportes").Refresh
se não fui claro, me desculpe, pois tenho pouco conhecimento nesse assunto.
Postado : 28/03/2013 7:14 am