excel - Compile error: Type mismatch (converting 32bit to 64bit VBA coding) -
this first time using vba need help. macro in excel convert file 1 excel extension another. have starting converting code 32 bit work in 64 bit , found online key parts change giving me compile errors: type mismatch , have no idea change. appreciated.
the error shows yellow arrow @ sub loopconvert() , cnttoconvert blue highlighted section. picture included. picture of error
option explicit 'created david miller (dlmille on e-e october, 2011) 'feel free use , share, please maintain appropriate acknowledgements author , link found code. sub loopconvert() dim fpath string dim fname string, fsaveasfilepath string, foriginalfilepath string dim wbook workbook, ffilestoprocess() string dim numconverted longptr, cnttoconvert longptr, longptr dim killonsave boolean, xmsg longptr, overwrite boolean, poverwrite boolean dim silentmode boolean dim removemacros boolean dim fromformat string, toformat string dim saveformat longptr dim wkb workbook, wks worksheet set wkb = thisworkbook set wks = wkb.sheets("control panel") removemacros = iif(wks.checkboxes("check box 1").value = 1, true, false) silentmode = iif(wks.checkboxes("check box 2").value = 1, true, false) killonsave = iif(wks.checkboxes("check box 3").value = 1, true, false) fromformat = wkb.names("fromformat").referstorange toformat = wkb.names("toformat").referstorange saveformat = iif(toformat = ".xls", xlexcel8, iif(toformat = ".xlsx", xlopenxmlworkbook, xlopenxmlworkbookmacroenabled)) application.displayalerts = false 'no user prompting, taking defaults application.screenupdating = false fpath = getfoldername("select folder " & fromformat & " " & toformat & " conversion") if fpath = "" msgbox "you didn't select folder", vbcritical, "aborting!" exit sub else fname = dir(fpath & "\*" & fromformat) if fname = "" msgbox "there aren't " & fromformat & " files in " & fpath & " directory", vbcritical, "aborting" exit sub else 'get file count of files processed, process them in next step if ucase(right(fname, len(fromformat))) = ucase(fromformat) 'to differentiate between dir *.xls , inadvertently *.xls??? redim preserve ffilestoprocess(cnttoconvert) string ffilestoprocess(cnttoconvert) = fname cnttoconvert = cnttoconvert + 1 end if fname = dir loop until fname = "" if cnttoconvert = 0 'we looking .xls , there .xls??? or nothing, abort msgbox "there aren't " & fromformat & " files in " & fpath & " directory", vbcritical, "aborting" exit sub end if if not silentmode xmsg = msgbox("there " & cnttoconvert & " " & fromformat & " files convert " & toformat & ". want delete " & fromformat & " files processed?", vbyesnocancel, "select option") killonsave = false 'already false, reminder in here! if xmsg = vbyes killonsave = true elseif xmsg = vbcancel goto processcomplete end if else poverwrite = true end if application.enableevents = false 'turn off events macros don't fire on excel file opens = 0 cnttoconvert - 1 'process each file conversion, displaying status progress... application.statusbar = "processing: " & + 1 & " of " & cnttoconvert & " file: " & fname fname = ffilestoprocess(i) 'open , convert file on error goto errhandler foriginalfilepath = fpath & "\" & fname 'you check see if save file exists, before open convert , save on top! overwrite = false fsaveasfilepath = fpath & "\" & mid(fname, 1, len(fname) - len(fromformat)) & toformat if not poverwrite if filefolderexists(fsaveasfilepath) xmsg = msgbox("file: " & fsaveasfilepath & " exists, overwrite?", vbyesnocancel, "hit yes overwrite, no skip, cancel quit") if xmsg = vbyes overwrite = true elseif xmsg = vbcancel goto processcomplete end if else overwrite = true end if else overwrite = poverwrite end if if overwrite set wbook = application.workbooks.open(foriginalfilepath) if removemacros , (toformat = ".xls" or toformat = ".xlsm") , (fromformat <> ".xlsx") 'use remove macro helper call removeallmacros(wbook) end if wbook.saveas filename:=fsaveasfilepath, fileformat:=saveformat wbook.close savechanges:=false numconverted = numconverted + 1 'optionally, can delete file converted if killonsave , fromformat <> toformat kill foriginalfilepath end if end if next end if end if processcomplete: on error goto 0 msgbox "completed " & numconverted & " " & fromformat & " " & toformat & " conversions", vbokonly application.enableevents = true 'uncomment if doing other conversions macros involved in source workbooks application.statusbar = false application.displayalerts = true application.screenupdating = false exit sub errhandler: application.statusbar = false msgbox "for reason, not open/save file: " & fpath & "\" & fname, vbcritical, "aborting!" resume processcomplete end sub
squidx3 helped me figure out needed change it. works thanks!
from this:
dim numconverted longptr, cnttoconvert longptr, longptr to this:
dim numconverted longptr, cnttoconvert long, long
Comments
Post a Comment