excel - VBA Error 6 Overflow macro -
i've used macro until few months ago, today doesn't work. error due part, namely
j = j + 1 how can solve problem?
this code:
sub stampavodafone() dim i, j integer dim fogliotmp worksheet dim contovodafone string dim foglioelenco worksheet dim percorsofile string dim percorsosalva string dim valcell variant dim strtesto string strtesto = "vuoi procedere con la stampa ?" & vbcr & "si - per procedere con la stampa dei dettagli telefonici" & _ vbcr & "no - per andare alla procedura successiva" if msgbox(strtesto, 68, "avvio stampavodafone") = vbyes 'procedura di stampa documenti = 1 set fogliotmp = activeworkbook.worksheets(i) if ucase(mid(fogliotmp.name, 1, 3)) = "tel" or ucase(mid(fogliotmp.name, 1, 3)) = "la " 'trovo dove sta la fine pagina j = 15 valcell = mid(cstr(fogliotmp.cells(j, 1).value), 1, 12) while (ucase(valcell) <> "totale costi") j = j + 1 valcell = mid(cstr(fogliotmp.cells(j, 1).value), 1, 12) loop fogliotmp.pagesetup .leftmargin = 0 .rightmargin = 0 .topmargin = 0 .bottommargin = 0 .printarea = "$a$1:$p$" & cstr(j) .leftheader = "" .centerheader = "" .rightheader = "" .leftfooter = "" .centerfooter = "" .rightfooter = "" .leftmargin = application.inchestopoints(0) .rightmargin = application.inchestopoints(0) .topmargin = application.inchestopoints(0) .bottommargin = application.inchestopoints(0) .headermargin = application.inchestopoints(0.511811023622047) .footermargin = application.inchestopoints(0.511811023622047) .printheadings = false .printgridlines = false .printcomments = xlprintnocomments .printquality = 600 .centerhorizontally = false .centervertically = false .orientation = xlportrait .draft = false .papersize = xlpapera4 .firstpagenumber = xlautomatic .order = xldownthenover .blackandwhite = false .zoom = false .fittopageswide = 1 .fittopagestall = 1 .printerrors = xlprinterrorsdisplayed .oddandevenpagesheaderfooter = false .differentfirstpageheaderfooter = false .scalewithdocheaderfooter = true .alignmarginsheaderfooter = false .evenpage.leftheader.text = "" .evenpage.centerheader.text = "" .evenpage.rightheader.text = "" .evenpage.leftfooter.text = "" .evenpage.centerfooter.text = "" .evenpage.rightfooter.text = "" .firstpage.leftheader.text = "" .firstpage.centerheader.text = "" .firstpage.rightheader.text = "" .firstpage.leftfooter.text = "" .firstpage.centerfooter.text = "" .firstpage.rightfooter.text = "" end application.printcommunication = true fogliotmp.printout end if = + 1 set fogliotmp = nothing loop while (i < activeworkbook.worksheets.count + 1) msgbox "ho terminato di stampare", vbexclamation, "macro" 'fine procedura stampa end if '-- strtesto = "vuoi procedere con l'estrazione dei file xlsx da spedire agli utenti?" & vbcr & _ "si - inizia la generazione dei file xlsx" & vbcr & _ "no - termina la macro" if msgbox(strtesto, 68, "genera xls") = vbyes 'inizio estrazione percorsofile = "c:\elencocellestrazione.xlsx" percorsosalva = "c:\estratti" contovodafone = application.activeworkbook.name '-- set foglioelenco = workbooks.open(percorsofile).worksheets(1) '-- = 1 windows(contovodafone).activate set fogliotmp = activeworkbook.worksheets(i) if ucase(mid(fogliotmp.name, 1, 3)) = "tel" strtesto = trim(mid(fogliotmp.name, 4, len(fogliotmp.name))) 'cerco il nome della persona j = 2 valcell = trim(cstr(foglioelenco.cells(j, 1).value)) while (ucase(valcell) <> ucase(strtesto) , ucase(valcell) <> "end list") j = j + 1 valcell = trim(cstr(foglioelenco.cells(j, 1).value)) loop if ucase(valcell) <> "end list" 'ho il nome dell'intestatario del telefono valcell = trim(cstr(foglioelenco.cells(j, 2).value)) strtesto = percorsosalva & valcell 'salvo il documento windows(contovodafone).activate sheets(fogliotmp.name).select sheets(fogliotmp.name).copy activeworkbook.saveas filename:=strtesto, fileformat:=xlopenxmlworkbookmacroenabled, createbackup:=false activewindow.close windows(contovodafone).activate end if end if '-- = + 1 set fogliotmp = nothing windows(contovodafone).activate loop while (i < activeworkbook.worksheets.count + 1) msgbox "ho terminato gli export xlsx", vbexclamation, "macro" end if end sub i have try change
dim i, j integer to
dim integer, dim j long but error changes 1004 in row:
valcell = trim(cstr(foglioelenco.cells(j, 1).value)) what escapes me?
in general, integer should not used in vba. smaller , slower long -> why use integer instead of long?
thus, redeclare integers long , overflow error should fixed:
dim long, j long concerning second error, try dim valcell string or give more information value.
Comments
Post a Comment