excel - VBA Open workbook with wildcard? -


i have .xlsx file in following directory:

g:\buying\food specials\2. planning\1. planning\1. planner\8. 2017\2017 planner.xlsx 

i point directory directory change depending on year is.

so directory become:

g:\buying\food specials\2. planning\1. planning\1. planner\9. 2018\2018 planner.xlsx 

to handle trying add wildcards path so:

g:\buying\food specials\2. planning\1. planning\1. planner\" & "*." & " " & year(date) & "\" 

my workbook not open. please can show me going wrong?

sub:

'find planner if len(finddepotmemo) set wb2 = workbooks.open(finddepotmemo, readonly:=true, updatelinks:=false) end if 

function:

function finddepotmemo() string      dim path string     dim findfirstfile string      path = "g:\buying\food specials\2. planning\1. planning\1. planner\" & "*." & " " & year(date) & "\"      findfirstfile = dir$(path & "*.xlsx")      while (findfirstfile <> "")          if instr(findfirstfile, "planner") > 0              finddepotmemo = path & findfirstfile             exit function          end if          findfirstfile = dir      wend  end function 

there many ways but, use approach:

function finddepotmemo() string      dim oldpath, temppath, newpath string     dim findfirstfile string     dim addint integer      ' assuming have path     ' use base path     ' , increment number , year in     oldpath = "g:\buying\food specials\2. planning\1. planning\1. planner\8. 2017"      ' extract 8. 2017 oldpath     temppath = mid(oldpath, instrrev(oldpath, "\") + 1)      ' year difference     addint = year(date) - cint(split(temppath, ".")(1))      ' add difference number , year     ' , have current year folder     newtemp = split(temppath, ".")(0) + addint & ". " & split(temppath, ".")(1) + addint      findfirstfile = dir$(path & "\" & "*.xlsx")      while (findfirstfile <> "")         if instr(findfirstfile, "test") > 0             finddepotmemo = path & findfirstfile             exit function         end if         findfirstfile = dir     wend  end function 

as i've added comments understand doing.


Comments

Popular posts from this blog

commonjs - How to write a typescript definition file for a node module that exports a function? -

openid - Okta: Failed to get authorization code through API call -

thorough guide for profiling racket code -