Compile error: Argument not optional vba excel -


i'm trying write code input image after checking info in each sheet of workbook. since added each code stoped working , started giving me compile error message, code works without each want automatic. can u guys help?

pt-br: estou tentando montar um código onde ele verificar todas planilhas e insere imagem conforme os dados em determinada célula. o código funciona sem o loop mas quero que seja todo automático e desde que inclui o each aparece esse erro de compilação. se puderem me ajudar com o que se trata agradeço.

sub foreachws() dim ws worksheet      each ws in activeworkbook.worksheets     call worksheet_selectionchange     next ws  end sub 

sub worksheet_selectionchange(byval target range)     on error resume next      if target.column = 2 , target.row = 1 ' onde clicar para buscar imagem          buscarimagemtavares (target.value)      end if  end sub 

sub buscarimagemtavares(produto string)     on error resume next     'autor: tavares      if range("b2") = "ok" 'verifica se celula b2 tem ok se sim não insere imagem novamente     exit sub     end if      dim imagem, caminhoimagem string      if len(produto) = 3 'acrescenta 00 antes cod produto         produto = "00" & produto     end if     if len(produto) = 4 'acrescenta 0 antes cod produto         produto = "0" & produto     end if      imagem = dir("\\clfssrvfar\engenharia\gestao_de_projetos\04. followup\09. arquivos para ferramentas\09.1 imagens\09.1.2 imagens produtos\" & produto & "*", vbdirectory)      caminhoimagem = "\\clfssrvfar\engenharia\gestao_de_projetos\04. followup\09. arquivos para ferramentas\09.1 imagens\09.1.2 imagens produtos\" & imagem        activesheet.pictures.insert(caminhoimagem) 'mostra imagem         'define tamanho e posição da imagem      .shaperange         .width = 75         .height = 115         .top = 7         .left = 715         '*above it's me trying make white background transparent*             'with .pictureformat             '.transparentbackground = true             '.transparencycolor = rgb(255, 0, 0)             'end         '.fill.visible = true         'end         'activesheet.shapes.range(array("picture 2")).select         'application.commandbars("format object").visible = false     end     end     if caminhoimagem <> "" 'após inserir imagem informa "ok" na b2 para não inserir de novo     range("b2").select     activecell.formular1c1 = "ok"     end if  end sub 

since want run sub buscarimagemtavares every worksheet have, have alter both subs foreachws , buscarimagemtavares.

foreachws:

sub foreachws()     dim ws worksheet      each ws in activeworkbook.worksheets         'here can directly call sub without sub worksheet_selectionchange         call buscarimagemtavares(ws, ws.cells(1,2).value)         'in buscarimagemtavares you´ll need ws reference work on right worksheet (otherwise youll work on selected one)     next ws  end sub 

buscarimagemtavares:

sub buscarimagemtavares(byval ws worrksheet, produto string)     'mind additional parameter 'ws'     on error resume next     'autor: tavares      'if range("b2") = "ok" 'verifica se celula b2 tem ok se sim não insere imagem novamente     if ws.range("b2") = "ok" 'here have use reference worksheet want use, otherwise alwys same used         exit sub     end if      ...      'you need reference here won#t use same worksheet on , on again     ws.pictures.insert(caminhoimagem) 'mostra imagem      ...      if caminhoimagem <> "" 'após inserir imagem informa "ok" na b2 para não inserir de novo         'range("b2").select         'activecell.formular1c1 = "ok"         'if don´t need cell in excel selected after programm finished should´nt use '.select' , '.selection' instead use this:         ws.range("b2").value= "ok" 'since aren´t adding formula should address '.value' property     end if      ...  end sub 

hope bit.


Comments

Popular posts from this blog

html - How to set bootstrap input responsive width? -

javascript - Highchart x and y axes data from json -

javascript - Get js console.log as python variable in QWebView pyqt -