This Blog

Syndication

Search

Tags

News

Community

Email Notifications

Archives

Grupos de Usuários

Blogs MVPs Brasil

Sites

April 2011 - Posts

Office 2010

Pois aproveite e faça o download de um trial (versão de avaliação) para conhecer o produto. Certamente irá adorá-lo.

Posted by paleo | with no comments
Filed under:

Digamos que você deseja salvar o conteúdo da coluna A em um arquivo texto com o nome da coluna B, na pasta da coluna C.

Neste caso insira o código abaixo em um módulo e execute a macro:

Sub XLS2TXT()
   Dim intRow As Integer
   intRow = 1
   Close
   Do Until IsEmpty(Cells(intRow, 1))
      Open Range("C1").Value & "\" & Cells(intRow, 2) & ".txt" For Output As #1
      Print #1, Cells(intRow, 1).Value
      Close
      intRow = intRow + 1
   Loop
End Sub

Posted by paleo | with no comments
Filed under:

Você já desejou identificar onde está a pasta de arquivos temporários do Windows através de sua planilha?

Coloque o seguinte código em um módulo e execute ele:

Declare Function GetTempPath _
        Lib "kernel32" Alias "GetTempPathA" _
       (ByVal nBufferLength As Long, _
        ByVal lpBuffer As String) As Long

Public Function fncGetTempPath() As String
  Dim PathLen As Long
  Dim WinTempDir As String
  Dim BufferLength As Long
  BufferLength = 260
  WinTempDir = Space(BufferLength)
  PathLen = GetTempPath(BufferLength, WinTempDir)
  If Not PathLen = 0 Then
     fncGetTempPath = Left(WinTempDir, PathLen)
  Else
     fncGetTempPath = CurDir()
  End If
End Function

Sub Test()
   MsgBox fncGetTempPath
End Sub

Posted by paleo | 3 comment(s)
Filed under:

Hoje respondi a uma pergunta no forum sobre como se criaria um timer para a execução de uma macro no Excel, pois aqui vai a solução:

Para que o timer seja iniciado ao abrir a planilha inclua este código em EstaPasta_de_trabalho:

Private Sub Workbook_Open()
    Call iniTimer
End Sub

Agora insira um módulo e nele adicione o seguinte código (Inserir -> Módulo):

Public Sub iniTimer()
    Application.OnTime EarliestTime:=Time + TimeValue("00:00:05"), Procedure:="minhaMacro"
End Sub


Public Sub minhaMacro()
    On Error Resume Next
    MsgBox ("Passou o tempo!")
    Application.OnTime EarliestTime:=Now + TimeValue("00:00:05"), Procedure:="minhaMacro"
End Sub

Public Sub paraTimer()
    Application.OnTime EarliestTime:=Now + TimeValue("00:00:01"), Procedure:="minhaMacro", Schedule:=False
End Sub

Naturalmente que o código de meu exemplo não faz muito sentido, pois apenas informa que o tempo passou, mas basta que você substitua a linha MsgBox ("Passou o tempo!"), pelo conteúdo que deseja executar com o timer, que seu código estará pronto.

Onde está o truque? No evento Application.OnTime

Onde o tempo é definido? No parâmetro EarliestTime

Espero que gostem e façam bom proveito!

Posted by paleo | with no comments
Filed under: ,