Advertisement
Guest User

Untitled

a guest
Dec 12th, 2019
217
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 7.50 KB | None | 0 0
  1. Sub ImportarDados()
  2. '
  3. Application.DisplayAlerts = False ' desativa as perguntas do excel ( salvar arquivo ? )
  4. Application.ScreenUpdating = False ' desabilita a visualizaçao da macro
  5.  
  6.  
  7. 'importa cotaçoes
  8. Sheets("Cotações").Select
  9. Cells.ClearContents
  10. Workbooks.Open ("https://docs.google.com/spreadsheets/d/e/2PACX-1vQBUuo9if0TUUTofNLVxq-aFnO4OJC4ht8DHxOD99jC79CwAhBXwccOUAFVSfZvmB-bZ-lIFocTMj9c/pub?output=xlsx")
  11. Cells.Copy
  12. Windows("Invest2.xlsm").Activate
  13. Cells.Select
  14. ActiveSheet.Paste
  15. Windows("pub").Close
  16.  
  17. 'importa tesouro direto
  18. Sheets("TTD").Select
  19. Cells.ClearContents
  20. Workbooks.Open ("https://docs.google.com/spreadsheets/d/e/2PACX-1vRmCnQdV5KZ4rXaJ9Md8CkIWWX5bP0tpH-EeQCBa7UHqfbkaBj9NTxpf1GCMgl0oSOL_izk4PAVfjOD/pub?output=xlsx")
  21. Sheets("TTD").Select
  22. Cells.Copy
  23. Windows("Invest2.xlsm").Activate
  24. Cells.Select
  25. ActiveSheet.Paste
  26. Windows("pub").Close
  27.  
  28. Sheets("Carteira").Select
  29. End Sub
  30.  
  31.  
  32. Sub AtualizarNetWorth()
  33.  
  34. Range("C2").Select
  35. Selection.End(xlDown).Offset(1, 0).Select
  36. ActiveCell.Value = Range("Track!B8").Value
  37.  
  38. Range("D2").Select
  39. Selection.End(xlDown).Offset(1, 0).Select
  40. ActiveCell.Value = Range("Track!B7").Value
  41.  
  42. Range("E2").Select
  43. Selection.End(xlDown).Offset(1, 0).Select
  44. ActiveCell.Value = Range("Track!B5").Value
  45.  
  46. Range("F2").Select
  47. Selection.End(xlDown).Offset(1, 0).Select
  48. ActiveCell.Value = Range("Track!B6").Value
  49.  
  50.  
  51.  
  52. End Sub
  53. Sub D2Macro()
  54.  
  55. Dim data As Variant
  56. Dim açoes As Variant
  57.  
  58. data = Range("B3").Value
  59. açoes = Range("B4").Value
  60.  
  61. Range("F3").Select
  62. Selection.End(xlDown).Select
  63.  
  64. If ActiveCell.Value <> data Then
  65. Range("B20").Value = açoes
  66.  
  67. Range("F2").Select
  68. Selection.End(xlDown).Offset(1, 0).Select
  69. ActiveCell.Value = data
  70. ActiveCell.Offset(0, 1).Value = açoes
  71.  
  72. Application.CutCopyMode = False
  73. Range("A1").Select
  74. Else
  75. End If
  76. Range("A3").Select
  77.  
  78. End Sub
  79.  
  80. Sub DMacro()
  81.  
  82. Dim Valores(10) As Variant
  83. Dim data As Variant
  84.  
  85. data = Range("C3").Value
  86.  
  87. Range("E3").Select
  88. Selection.End(xlDown).Select
  89.  
  90. If ActiveCell.Value <> data Then
  91. For i = 3 To 10
  92. Valores(i) = Cells(i, 3).Value
  93. Cells(2, i + 2).Select
  94. Selection.End(xlDown).Offset(1, 0).Select
  95. ActiveCell.Value = Valores(i)
  96. Next i
  97. Else
  98. End If
  99.  
  100. Range("A3").Select
  101. End Sub
  102.  
  103. Sub AtualizarInfo()
  104.  
  105. Range("B2").Select
  106. Selection.End(xlDown).Offset(1, 0).Select
  107. ActiveCell.Value = Range("Track!B1")
  108. ActiveCell.Offset(0, 2).Value = Range("Track!B2")
  109. ActiveCell.Offset(0, 4).Value = Range("Track!B3")
  110. ActiveCell.Offset(0, 6).Value = Range("Track!B4")
  111. ActiveCell.Offset(0, 8).Value = Range("Track!B5")
  112.  
  113. End Sub
  114.  
  115. Sub EnviarRelatorio()
  116.  
  117.  
  118. Dim outlook As Object
  119. Dim newEmail As Object
  120. Dim xInspect As Object
  121. Dim pageEditor As Object
  122. Dim VariaçaoDia As Variant
  123.  
  124. 'data
  125. dia = Day(Range("F2"))
  126. mes = Month(Range("F2"))
  127. ano = Year(Range("F2"))
  128. data = Range("F2")
  129.  
  130. If dia < 10 Then
  131. dia = "0" & dia
  132. End If
  133.  
  134. If mes < 10 Then
  135. mes = "0" & mes
  136. End If
  137.  
  138. VariaçaoDia = Range("G2").Value * 100
  139.  
  140. 'ExportarPDF
  141. ActiveSheet.ExportAsFixedFormat Type:=xlTypePDF, Filename:= _
  142. "D:\Desktop\investimentos\Relatórios\Relatório" & ano & mes & dia & ".pdf", Quality:=xlQualityStandard _
  143. , IncludeDocProperties:=True, IgnorePrintAreas:=False, OpenAfterPublish:= _
  144. True
  145.  
  146.  
  147. Set outlook = CreateObject("Outlook.Application")
  148. Set newEmail = outlook.CreateItem(0)
  149.  
  150. With newEmail
  151. .To = "renan_morettopereira@hotmail.com"
  152. .CC = "renan@tropicoinvest.com"
  153. .BCC = ""
  154. .Subject = "Relatório " & Format(Range("F2"), "dd-mm-yy") & " " & VariaçaoDia & "%"
  155. .Attachments.Add "D:\Desktop\investimentos\Relatórios\Relatório" & ano & mes & dia & ".pdf"
  156. .Attachments.Add "D:\Desktop\investimentos\Invest2.xlsm"
  157. .HTMLBody = ""
  158. .display
  159.  
  160. Set xInspect = newEmail.GetInspector
  161. Set pageEditor = xInspect.WordEditor
  162.  
  163. Sheets("Resumo").Range("F2:P60").Copy
  164.  
  165. pageEditor.Application.Selection.End = pageEditor.Application.Selection.Start
  166. pageEditor.Application.Selection.PasteAndFormat (wdFormatPlainText)
  167. .display
  168. .Send
  169. Set pageEditor = Nothing
  170. Set xInspect = Nothing
  171. End With
  172.  
  173. Set newEmail = Nothing
  174. Set outlook = Nothing
  175. Application.CutCopyMode = False
  176.  
  177.  
  178.  
  179.  
  180.  
  181.  
  182.  
  183.  
  184. End Sub
  185. Sub AtualizarVarTabela()
  186.  
  187. 'data
  188. Sheets("Resumo").Select
  189. dia = Day(Range("F2"))
  190. mes = Month(Range("F2"))
  191. ano = Year(Range("F2"))
  192. data = Range("F2")
  193. Dim dmes As Date
  194. Dim dano As Date
  195. Dim d6m As Date
  196. Dim d12m As Date
  197. Dim vames As Variant
  198. Dim vaano As Variant
  199. Dim va6m As Variant
  200. Dim va12m As Variant
  201. Dim vfiimes As Variant
  202. Dim vfiiano As Variant
  203. Dim vfii6m As Variant
  204. Dim vfii12m As Variant
  205. Dim vinvmes As Variant
  206. Dim vinvano As Variant
  207. Dim vinv6m As Variant
  208. Dim vinv12m As Variant
  209. Dim lin As Integer
  210. Dim var As Variant
  211.  
  212.  
  213. If dia < 10 Then
  214. dia = "0" & dia
  215. End If
  216.  
  217. If mes < 10 Then
  218. mes = "0" & mes
  219. End If
  220.  
  221. d6m = DateAdd("m", -6, data)
  222. d12m = DateAdd("yyyy", -1, data)
  223. dmes = DateSerial(ano, mes, 1)
  224. dano = DateSerial(ano, 1, 1)
  225.  
  226. Sheets("D").Select
  227. Range("E3").Select
  228. Selection.End(xlDown).Select
  229. lin = ActiveCell.Row
  230.  
  231. 'açoes
  232. vmes = loopv(lin, 15, dmes)
  233. vano = loopv(lin, 15, dano)
  234. v6m = loopv(lin, 15, d6m)
  235. v12m = loopv(lin, 15, d12m)
  236.  
  237. 'fiis
  238. vfiimes = loopv(lin, 17, dmes)
  239. vfiiano = loopv(lin, 17, dano)
  240. vfii6m = loopv(lin, 17, d6m)
  241. vfii12m = loopv(lin, 17, d12m)
  242.  
  243. 'invest
  244. vinvmes = loopv(lin, 25, dmes)
  245. vinvano = loopv(lin, 25, dano)
  246. vinv6m = loopv(lin, 25, d6m)
  247. vinv12m = loopv(lin, 25, d12m)
  248.  
  249. 'colar na tabela
  250. Sheets("Resumo").Select
  251. Range("L1000").Select
  252. Selection.End(xlUp).Select
  253.  
  254. ActiveCell.Value = vinvmes
  255. ActiveCell.Offset(0, 1).Value = vinvano
  256. ActiveCell.Offset(0, 2).Value = vinv6m
  257. ActiveCell.Offset(0, 3).Value = vinv12m
  258.  
  259. ActiveCell.Offset(-1, 0).Value = vfiimes
  260. ActiveCell.Offset(-1, 1).Value = vfiiano
  261. ActiveCell.Offset(-1, 2).Value = vfii6m
  262. ActiveCell.Offset(-1, 3).Value = vfii12m
  263.  
  264. ActiveCell.Offset(-2, 0).Value = vmes
  265. ActiveCell.Offset(-2, 1).Value = vano
  266. ActiveCell.Offset(-2, 2).Value = v6m
  267. ActiveCell.Offset(-2, 3).Value = v12m
  268.  
  269. End Sub
  270. Public Function loopv(lin As Integer, col As Integer, ddata As Date) As Variant
  271.  
  272. var = 0
  273. For i = 1 To lin
  274. If Cells(i, 5) > ddata Then
  275. var = ((1 + var) * (1 + Cells(i, col))) - 1
  276. Else
  277. End If
  278. Next i
  279. loopv = var
  280.  
  281. End Function
  282.  
  283.  
  284. Sub AtualizarPlanilhaMain()
  285.  
  286. Sheets("Carteira").Select
  287. Call ImportarDados
  288.  
  289. Sheets("D").Select
  290. Call DMacro
  291.  
  292. Sheets("D2").Select
  293. Call D2Macro
  294.  
  295. Sheets("Resumo").Select
  296. Call AtualizarVarTabela
  297.  
  298. MsgBox "Planilha atualizada!"
  299.  
  300. End Sub
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement